"ankit_jain_gzb" <an************@hotmail.com> wrote in message
news:11********************@g44g2000cwa.googlegrou ps.com
Hi
Iam not able to understand why the following code gives compile
problem.
Thanks
Ankit Jain
class B;
class A{
public:
friend class B;
B* x;
A()
{
x = new B(3)
}
};
The problem is that at the point at which you define the A constructor, the
B constructor has not yet been declared.
class B{
public:
B(int i)
{
}
};
int main()
{
return 0;
}
error coming in vc++ (6.0) is --> error C2514: 'B' : class has no
constructors
Try doing it in this order:
class B;
class A{
public:
friend class B;
B* x;
A();
};
class B{
public:
B(int i)
{}
};
// Now the B constructor has been declared,
// we can use it in the A constructor. I declare
// it inline because functions defined in the
// class declaration, as per your version,
// are implicitly inline.
inline A::A()
{
x = new B(3);
}
int main()
{
return 0;
}
--
John Carson