cthulhu_54
August 19th, 2010, 04:40 PM
I have two classes, one that defines the x,y,z direction (of a particle) and one that defines left, right. Now I want to put them together to give:
object.x = 1
object.x.l = 4.5 //(for left)
object.x.r = 32
As I understand it this will not work. So I've written the following program in C++, but it will not compile:
using namespace std;
class Direction{
public:
Direction(void);
double r; //right
double l; //left
};
class Particle{
public:
Particle(void);
int x;
int y;
int z;
Direction dir;
};
int main(){
Particle test;
test.x = 5;
test.y = 11;
test.z = 3; //OK, works
Direction temp;
temp.r = 1;
temp.l = 5.3; //OK, works
test.x.dir = temp; //AARRGHHH!
test.x.dir.r = 32; //AARRGHHH!
return 0;
}
And I get the error:
request for member ‘dir’ in ‘test.Particle::x’, which is of non-class type ‘int’
for the two last lines.
I've googled it (omitting the specifics in my error message above), and the first 30-40 hits are all about mixing up the -> with . operator, or declaring things like Particle() test, or Particle test(), but that can't be the case here can it?
What did I do wrong? Any clue would be greatly appreciated!
object.x = 1
object.x.l = 4.5 //(for left)
object.x.r = 32
As I understand it this will not work. So I've written the following program in C++, but it will not compile:
using namespace std;
class Direction{
public:
Direction(void);
double r; //right
double l; //left
};
class Particle{
public:
Particle(void);
int x;
int y;
int z;
Direction dir;
};
int main(){
Particle test;
test.x = 5;
test.y = 11;
test.z = 3; //OK, works
Direction temp;
temp.r = 1;
temp.l = 5.3; //OK, works
test.x.dir = temp; //AARRGHHH!
test.x.dir.r = 32; //AARRGHHH!
return 0;
}
And I get the error:
request for member ‘dir’ in ‘test.Particle::x’, which is of non-class type ‘int’
for the two last lines.
I've googled it (omitting the specifics in my error message above), and the first 30-40 hits are all about mixing up the -> with . operator, or declaring things like Particle() test, or Particle test(), but that can't be the case here can it?
What did I do wrong? Any clue would be greatly appreciated!