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++ / May 2004

Tip: Looking for answers? Try searching our database.

Forward declarations

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JoNinty - 17 May 2004 18:01 GMT
Class S contains a pointer to class main
Class main contains and instance of class
I therefore include a forward reference in S of main
The catch is I want to call a method in main from s and if I do this I get an erro
use of undefined type 'Main'
So how can I call a method in main from S and if I cant whats the point in being able to store a pointer to it?
Rudy Ray Moore - 17 May 2004 18:38 GMT
> I therefore include a forward reference in S of main.

This should be in the .h file

> The catch is I want to call a method in main from s and if I do this I get an error

No problem.

Try this:
1) in s.cpp: #include<main.h>
2) in main.cpp: #inlcude<s.h>

Do not try this:
1) in s.h: #include<main.h>
2) in main.h: #inlcude<s.h>

Rudy

> Class S contains a pointer to class main.
> Class main contains and instance of class S
> I therefore include a forward reference in S of main.
> The catch is I want to call a method in main from s and if I do this I get an error
> use of undefined type 'Main'.
> So how can I call a method in main from S and if I cant whats the point in being able to store a pointer to it?
JoNinty - 18 May 2004 10:01 GMT
Thank you. A well placed #include solved this
You never see this type of thing in books do you?
Matt Osborn - 18 May 2004 14:13 GMT
Large-Scale C++ Software Design by John Lakos

> Thank you. A well placed #include solved this !
> You never see this type of thing in books do you?
mccoyn - 17 May 2004 19:46 GMT
You can't define the function inline.  The following should work

class main

class S
 main* m
 void foo()
}

class main
 S s
 int i

void S::foo()
 do_something(m->i)
}

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.