Forward declaration in Managed C++

  • Thread starter Thread starter shree kame
  • Start date Start date
S

shree kame

I have a managed class A and inside A, I'm declaring an object of class
B. B has been forward declared.

Namespace X::Y::Z
{
__gc class B;

__gc class A
{
public:
A()
{
B *b = new B();
}

};

__gc class B
{
public:
B( )
{
}
};
}

The compiler complains
'X::Y::Z::A::B' : no appropriate default constructor available

Any clues??
Thanks
shree
 
shree,

I have a managed class A and inside A, I'm declaring an object of class
B. B has been forward declared.

Namespace X::Y::Z
{
__gc class B;

__gc class A
{
public:
A()
{
B *b = new B();
}

};

__gc class B
{
public:
B( )
{
}
};
}

The compiler complains
'X::Y::Z::A::B' : no appropriate default constructor available

Any clues??


First of all, this is not the appropriate group for these questions.
Instead, try the microsoft.public.dotnet.languages.vc group (followups set
accordingly).

As for the answer: the compiler is right. The problem is that you're
defining A's constructor inline, so at the point you're using B::B(), it has
indeed not been defined yet. Remember that C++ does compilation pretty much
module by module.

Obviously, the easy answer is *not* to define A::A() inline....
 
Back
Top