In following code,.
Is there any way to use A::print() inside B::B() ?
===========================================
Expand|Select|Wrap|Line Numbers
- struct A;
- struct B {
- B(A *pA) {
- cout<<"pA = "<<pA<<endl;
- cout<<"pA->print() = "<<pA->print()<<endl; // throwing error
- }
- };
- struct A {
- void print() { cout<<"Hello World\n"; }
- };
- int main()
- {
- B obj(new A);
- }
Error:
In constructor `B::B(A*)':
error: invalid use of undefined type `struct A'
error: forward declaration of `struct A'