OK, this should be a simple one for the experienced programmers among you!
I have two classes; move and node.
'move' contains two integer members.
'node' contains one 'move' object as a member.
How can I access the integer values of the 'move' object which is a member of the 'node' class using pointers?
I have written some code (below) where I have created and linked the objects, but I get a compiler error when I try to access the member class.
The compiler error message I get is:
Line 45 "request for member `getData' in `b', which is of non-class type `node()(move*)'"
I am a beginner at C++, so I have the feeling this is probably something really simple.
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 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <string>
using namespace std;
class move;
class node;
///////////// CLASS MOVE ///////////////
class move {
public:
move();
move(int, int);
int NUMBER1;
int NUMBER2;
};
move::move(){}
move::move(int iFrom, int iTo)
{
NUMBER1 = iFrom;
NUMBER2 = iTo;
}
///////////// CLASS NODE //////////////
class node
{
private:
move *data;
public:
node(move *);
move getData();
};
node::node(move *object) {data = object;}
move node::getData() {return *data;}
//////////TEST ROUTINE///////////////////
int main(int argc, char *argv[])
{
move a(8,23);
node b(move *a);
int iOutput = b.getData()->NUMBER1; //ERROR LINE!!
string s;
cin >> s;
return 0;
}
|