Forward Declarations in Managed C++

G

Guest

Hi again,

Maybe I missed something, but I cannot do a forward declaration in managed
C++.

By doing:

namespace Namespace
{

public __gc class A; // forward declaration

public __gc class B // B class, that uses A in constructor
{
public: B(A* a) : mA(a) {}
private A* mA;
};

public __gc class A // A class definition
{
....
};

}

Results in the following errors:


* warning C4677: 'B': signature of non-private function contains assembly
private type 'Namespace::A'
* see declaration of 'Namaspace::A'
* assembly access specifier modified from 'private'

A is clearly forward-declarated as public.

Any clue?

Thanks.
 
T

Tomas Restrepo \(MVP\)

Libertadrian said:
Hi again,

Maybe I missed something, but I cannot do a forward declaration in managed
C++.

By doing:

namespace Namespace
{

public __gc class A; // forward declaration

public __gc class B // B class, that uses A in constructor
{
public: B(A* a) : mA(a) {}
private A* mA;
};

public __gc class A // A class definition
{
...
};

}

Results in the following errors:


* warning C4677: 'B': signature of non-private function contains assembly
private type 'Namespace::A'
* see declaration of 'Namaspace::A'
* assembly access specifier modified from 'private'

A is clearly forward-declarated as public.

Any clue?

Your code, as is, compiles fine (adding a missing : in B), and gives no
warning.
The error only pops up if, when forward declaring A, you ommit the "public"
specifier, so that it defaults to private and then conflicts with the use of
it and how it is later defined.
 
G

Guest

Thanks Thomas (x2)!!!

Yep, I reviewed my code (not the same I pasted here), and I found I was doing:

public __gc class B // B class, that uses A in constructor
{
public: B(class A* a) : mA(a) {}
private: A* mA;
};

// the 'class A*' in B::ctor (old style fwd-decl) was causing trouble.

But even removing that, I got

"assembly access specifier modified from 'private'"

You don't get any warnings? How come?
 
G

Guest

Forget the previous post, I found I was also doing

private: class *A mA;

in class B.

Thanks
 

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