Forward declaration in Managed C++

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
 
T

Tomas Restrepo \(MVP\)

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top