Object as Member Variable

closed account (3872Nwbp)
I believe what I am trying to do is called a "Member Initialization List", but I can't seem to implement it correctly. I'm using Code::Blocks 10.05 with g++ 4.7.2 on Linux.

I have two classes, A and B. A contains members of B. Each class has a *.h and a *.cpp file.

I've included what I believe to be relevant:

A's *.h
1
2
3
4
5
6
7
class A : public B
{
   public:
      A();
      B one;
      B two;
}


A's *.cpp
1
2
3
4
A::A() : A::one(0), A::two(1)
{
   // initialization of other members
}


When I try to build, I get syntax complaints:
1
2
3
4
5
In constructor ‘A::A()’:
error: expected class-name before ‘(’ token
error: expected ‘{’ before ‘(’ token
error: expected constructor, destructor, or type conversion before ‘,’ token
error: expected constructor, destructor, or type conversion before ‘(’ token

Does anyone have an idea of where I may be going wrong?
If more info is needed, I'll be happy to provide.

Thank you.
A::A() : one(0), two(1)
closed account (3872Nwbp)
Oh you're kidding. I could've sworn I tried that. Oh well. Thanks.
Topic archived. No new replies allowed.