0

I created a header called One.h to include my class of a 3d vector, and then I use a source file called main.cxx to input the class into an int function. However, I keep getting these errors, and I have been trying for days to fix it but I can't. I am new to C++.

/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;
 ^ 

One.h

#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 arguments 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

#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;
}
marc_s
760k185 gold badges1.4k silver badges1.5k bronze badges
asked Feb 23, 2021 at 20:57
3

1 Answer 1

5

You have a collision between std::distance and your float distance(Vector3d v1, Vector3d v2) function.

Removing using namespace std; and qualifying with std:: where necessary will resolve that.

This is an example of why it is recommended to use rarely, if ever, using namespace std;.

answered Feb 23, 2021 at 21:04
Sign up to request clarification or add additional context in comments.

1 Comment

Omg thank you it works perfect now, Learning more and more everyday I really appreciate it

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.