Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2004

Tip: Looking for answers? Try searching our database.

Forward Declarations in Managed C++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Libertadrian - 22 Sep 2004 02:15 GMT
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.
Tomas Restrepo \(MVP\) - 22 Sep 2004 03:01 GMT
> Hi again,
>
[quoted text clipped - 31 lines]
>
> 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.

Signature

Tomas Restrepo
tomasr@mvps.org

Libertadrian - 22 Sep 2004 03:25 GMT
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?

"Tomas Restrepo (MVP)" wrote:

> > Hi again,
> >
[quoted text clipped - 37 lines]
> specifier, so that it defaults to private and then conflicts with the use of
> it and how it is later defined.
Libertadrian - 22 Sep 2004 03:33 GMT
Forget the previous post, I found I was also doing

private:  class *A mA;

in class B.

Thanks

> Thanks Thomas (x2)!!!
>
[quoted text clipped - 57 lines]
> > specifier, so that it defaults to private and then conflicts with the use of
> > it and how it is later defined.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.