C2039 error that shouldn't be

I am getting an error that
error C2039: 'iterator_category' : is not a member of 'City'

the problem is, I'm not calling an iterator of any kind in my program any more.

1
2
3
4
5
6
7
struct City
{ // error points here
  string name; 
  double lat;
  double lon;
  City(string a, double b, double c){name = a; lat = b; lon = c;}
};


I have no clue as to why. Any help?
Please post the full compiler output, and the code that deals with the City struct.

1>------ Build started: Project: Homework 2, Configuration: Debug Win32 ------
1>  Driver.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(373): error C2039: 'iterator_category' : is not a member of 'City'
1>          c:\users\jeremy daugherty\desktop\dropbox\cpp\cs253\homework_2\mst.h(7) : see declaration of 'City'
1>          c:\users\jeremy daugherty\desktop\dropbox\cpp\cs253\homework_2\driver.cpp(755) : see reference to class template instantiation 'std::iterator_traits<_Iter>' being compiled
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(373): error C2146: syntax error : missing ';' before identifier 'iterator_category'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(373): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(373): error C2602: 'std::iterator_traits<_Iter>::iterator_category' is not a member of a base class of 'std::iterator_traits<_Iter>'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(373) : see declaration of 'std::iterator_traits<_Iter>::iterator_category'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(373): error C2868: 'std::iterator_traits<_Iter>::iterator_category' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(374): error C2039: 'value_type' : is not a member of 'City'
1>          c:\users\jeremy daugherty\desktop\dropbox\cpp\cs253\homework_2\mst.h(7) : see declaration of 'City'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(374): error C2146: syntax error : missing ';' before identifier 'value_type'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(374): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(374): error C2602: 'std::iterator_traits<_Iter>::value_type' is not a member of a base class of 'std::iterator_traits<_Iter>'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(374) : see declaration of 'std::iterator_traits<_Iter>::value_type'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(374): error C2868: 'std::iterator_traits<_Iter>::value_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(375): error C2039: 'difference_type' : is not a member of 'City'
1>          c:\users\jeremy daugherty\desktop\dropbox\cpp\cs253\homework_2\mst.h(7) : see declaration of 'City'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(375): error C2146: syntax error : missing ';' before identifier 'difference_type'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(375): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(375): error C2602: 'std::iterator_traits<_Iter>::difference_type' is not a member of a base class of 'std::iterator_traits<_Iter>'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(375) : see declaration of 'std::iterator_traits<_Iter>::difference_type'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(375): error C2868: 'std::iterator_traits<_Iter>::difference_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(377): error C2039: 'pointer' : is not a member of 'City'
1>          c:\users\jeremy daugherty\desktop\dropbox\cpp\cs253\homework_2\mst.h(7) : see declaration of 'City'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(377): error C2146: syntax error : missing ';' before identifier 'pointer'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(377): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(377): error C2602: 'std::iterator_traits<_Iter>::pointer' is not a member of a base class of 'std::iterator_traits<_Iter>'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(377) : see declaration of 'std::iterator_traits<_Iter>::pointer'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(377): error C2868: 'std::iterator_traits<_Iter>::pointer' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(378): error C2039: 'reference' : is not a member of 'City'
1>          c:\users\jeremy daugherty\desktop\dropbox\cpp\cs253\homework_2\mst.h(7) : see declaration of 'City'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(378): error C2146: syntax error : missing ';' before identifier 'reference'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(378): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(378): error C2602: 'std::iterator_traits<_Iter>::reference' is not a member of a base class of 'std::iterator_traits<_Iter>'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(378) : see declaration of 'std::iterator_traits<_Iter>::reference'
1>          with
1>          [
1>              _Iter=City
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(378): error C2868: 'std::iterator_traits<_Iter>::reference' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Iter=City
1>          ]


Sorry for the wall of text but that is the error in complete, it's pointing to an illegal call I'm not making repeatedly.

The code that deals with it is this.

1
2
3
4
5
6
7
double distance(City a , City b)
{
  double latit = b.lat - a.lat;
  double longit = b.lon - a.lon;
  
  return sqrt( pow(latit,2) + pow(longit,2) );
}


And the struct in my first post, outside of that and a arr[i].name
in other overly long functions that barely call it and a large array that is initializes like such
1
2
3
4
5
  City cityArr[] = 
    { City("Washington, D.C.",  38.85,  77.0333),
    City("Alexander City, AL",  32.95,  85.95),
    City("Anniston, AL",  33.5833,  85.85),
    City("Auburn, AL",  32.6,  85.5),

731 times
So the problems you have are to do with:

mst.h(7) - line 7 in file mst.h. Is this the declaration of the City struct? Where are you calling the constructor of this struct?

driver.cpp(755) - is that the distance function you have shown above?

xutility(378) Why is this include file needed? What code is using this include file?

c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(378): error C2868: 'std::iterator_traits<_Iter>::reference' : illegal syntax for using-declaration; expected qualified-name
1> with
1> [
1> _Iter=City
1> ]


Do you have an _Iter any whre in your code? If so starting a variable name with an underscore is a bad idea because it might clash with a variable i a header file or namespace.

Do you have a using namespace std; in your code? Might be time to avoid doing that - use std:: before each std thing instead. Or have a using std::cout; as an example.

HTH

Yes, it is the City struct, other than the constructor there is nothing else. The only time the city constructor is called is when I make the city array (the second code on the second post).

Yes, that is the distance function above, the only time I call the numerical data from it.

That's the thing, it was included when I was using a list, but I got rid of that and the list include. At least I'm assuming as it has stuff pertaining to the iterator and other <list> things.

With the _Iter that is never called, and I never intended to use that, I do know that is bad coding for non-basic code. As for the iterator it is probably for, I don't call iterators in my program at all, there is simply no point when I'm not using a list anymore.

I am using namespace std; and not std::cout. I don't really know how the namespace thing works and I also don't know how that would cause my problem.
My guess is your distance function is clashing with std::distance (which works on iterators...) Try changing the name or getting rid of the using directive.
The only thing I can think of now is that xutility is being included by some other include file - but there must be a reason that the compiler wants to use it. Are you sure you have the right versions of each of your code files?

The thing with namespace std is that it brings heaps of stuff into the global namespace - increasing the risk of a name clash. So it is best to use one of the methods shown above. It may not be a cause of your problem, but it would be good if you started do this preferred method.

Instead of initialising the array with function calls, put the function calls inside a loop and assign the objects.

The other thing to do is use a vector (instead of an array) which you can push object into.

HTH

Edit: Ninja by cire
Last edited on
I know there is a template function in the Standard C++ library called distance
That function takes two iterators.

I'm wondering if the compiler is getting confused between your distance function and the function of the same name from the standard library.
Okay, it was the distance call that was messing things up. Thanks guys.
Topic archived. No new replies allowed.