Forward Declarations in Managed C++

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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.
 
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?
 
Forget the previous post, I found I was also doing

private: class *A mA;

in class B.

Thanks
 
Back
Top