error: ‘class Rec’ has no member named ‘mycity’

I want to print *(*it)->mycity
, but it said has no member named ‘mycity’?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include<iostream>
#include<vector>


using std::vector;
using std::cout;
using std::endl;
using std::string;

class Rec {

public://
void print()
{
vector<Rec*>::iterator it = vec.begin(); 
/* operate begin() end() && 
Declare vector name =vec */
while ( it != vec.end()) 
{ std::cout << *(*it)->mycity << std::endl; }
}

private://
vector <Rec*> vec; //in private
class Anotherclass {
public:
string* mycity;
};

};

int main(int argc, char *argv[])
{
if ( argc != 2)
{ std::cout << "usage: " << argv[0] << "<filename>" << std::endl; return 0;}

std::cout << std::endl;
}
What don't you understand about the error message? You haven't defined a variable with the name of mycity in your Rec class. The mycity variable in your Anotherclass class would not be the same, plus you never defined an instance of Anotherclass either.

By the way what is with all of those pointers.

Why are you trying to create a vector of Rec inside your Rec class. Normally your vector would be external to the class.

Topic archived. No new replies allowed.