T
thegreatgonzo
Hi i am not very skilled in forward declarations. I have this program:
class C
{
public:
C()
{
//Do something usefull
}
};
class B;
class A : public C
{
public:
A(B *parent)
{
myParent = parent;
if(parent->number == 10)
return;
}
B *myParent;
};
class B : public C
{
public:
B()
{
number = 5;
}
int number;
};
int main()
{
B myB;
myB.number = 10;
return 0;
}
this code produces the following errors:
test3.cpp: In constructor ‘A::A(B*)’: test3.cpp:18: error: invalid use of
undefined type ‘struct B’ test3.cpp:10: error: forward declaration of
‘struct B’
on g++ 4.1.2, running ubuntu;
can anyone help me please?
grz,
Leon
class C
{
public:
C()
{
//Do something usefull
}
};
class B;
class A : public C
{
public:
A(B *parent)
{
myParent = parent;
if(parent->number == 10)
return;
}
B *myParent;
};
class B : public C
{
public:
B()
{
number = 5;
}
int number;
};
int main()
{
B myB;
myB.number = 10;
return 0;
}
this code produces the following errors:
test3.cpp: In constructor ‘A::A(B*)’: test3.cpp:18: error: invalid use of
undefined type ‘struct B’ test3.cpp:10: error: forward declaration of
‘struct B’
on g++ 4.1.2, running ubuntu;
can anyone help me please?
grz,
Leon