Having errors with using a header and source files

  c++

Okay so I created a header called One.h file to include my class of a 3d vector and then I use a source file called main.cxx to input the class into a int function. However I keep getting these errors and I been trying for days to fix it but I can’t. I am new to c++ so do not be so harsh.

/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:165:53:
error: no type named ‘iterator_category’ in ‘class Vector3d’
       typedef typename _Iterator::iterator_category iterator_category;
                                                     ^ 
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:166:53: error:
no type named ‘value_type’ in ‘class Vector3d’
       typedef typename _Iterator::value_type        value_type;
                                                     ^ 
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:167:53: error:
no type named ‘difference_type’ in ‘class Vector3d’
       typedef typename _Iterator::difference_type   difference_type;
                                                     ^ 
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:168:53: error:
no type named ‘pointer’ in ‘class Vector3d’
       typedef typename _Iterator::pointer           pointer;
                                                     ^ 
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:169:53: error:
no type named ‘reference’ in ‘class Vector3d’
       typedef typename _Iterator::reference         reference;
                                                     ^ 

This file is my One.h header file

#include <iostream>
#include <math.h>

#include <stdio.h>



 using namespace std;



class Vector3d {

// Class of a Euclidean 3d vector

private:

float x;

float y;

float z;

// The x y and z components that are our private data members

public:

Vector3d(float xaxis, float yaxis, float zaxis)

{

    x = xaxis;

    y = yaxis;

    z = zaxis;

}

// Creating a constructor to help access the members of the class



float getx() { return x; }

float gety() { return y; }

float getz() { return z; }

// Used to actually get the values of our members so functions to print out values

float normVector()

{

    float result = sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));

    return result;

    // The norm of the vector an function with in the class

}

};



float distance(Vector3d v1, Vector3d v2)

// We have a function outside the class, the arguements are objects of the same class but two different objects

// so like two different vectors

 {

 return sqrt(

  pow(v1.getx() - v2.getx(), 2)

+ pow(v1.gety() - v2.gety(), 2)

+ pow(v1.getz() - v2.getz(), 2)

   );

   // In the function we can use v1.getx and v2.getx to access and put the values of the private members in the class

  // This is the distance formula between to vectors

main.cxx file

 #include "One.h"


int main()

{

Vector3d v1(2, 2, 2);

v1.getx();

v1.gety();

v1.getz();

 // Our vector one with defiining values



v1.normVector();

cout << "  Components and the norm of my first vector     " << endl;

cout << " X1 axis t:t "   << v1.getx() << endl;

cout << " Y1 axis  t:t "  << v1.gety() << endl;

cout << " Z1 axis   t:t "   << v1.getz() << endl;



cout << " The norm of our first vector  t:t " << v1.normVector() << endl;



Vector3d v2(3, 3, 3);

v2.getx();

v2.gety();

v2.getz();



cout << "  Components and the norm of my second vector     " << endl;



 cout << " X2  axis t:t " << v2.getx() << endl;

cout << " Y2  axis  t:t " << v2.gety() << endl;

cout << " Z2  axis t:t " << v2.getz() << endl;

cout << " The norm of our second vector " << v2.normVector() << endl;



cout << "The distance between vector one and two t:t " << distance(v1, v2) << " units." << endl;

 // Here we can use the cout operator to compile the distance formula we created earlier and make it visible on the screen

return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT