#### Archived

This topic is now archived and is closed to further replies.

# C++ Class question

This topic is 6263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

(i thought i already posted this before but i can''t find it) If you have:
  class FOO { public: BAR MyBar; } class BAR { public: FOO MyFoo; } 
the program will crash when it hits
  BAR MyBar; 
because the BAR class has not yet been defined. Is there some way how I could declare classes at the top (like a function declaration for classes), or is there another way around this?

##### Share on other sites
Well, you can use forward declarations:

  class foo;class bar;class foo{ ...};class bar{ ...};

However, in the example you gave, I don't see how the compiler could ever instantiate either of the objects. One depends on the other which depends on the one, and so forth. But if those members were pointers to foo and bar, that'd be fine.

Edited by - merlin9x9 on July 26, 2001 5:41:51 PM

##### Share on other sites
yes as a matter of fact, they are pointers.

sweet that worked awesome
thanks dude

1. 1
2. 2
3. 3
frob
20
4. 4
Rutin
19
5. 5

• 32
• 13
• 10
• 9
• 18
• ### Forum Statistics

• Total Topics
632555
• Total Posts
3007065

×