cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Calling a class from a class?
Calling a class from a class?
Sep 14, 2008 at 2:27am UTC
slythfox
(2)
I'm working on a card game program. I have a class called Deck and a class called Card
I'm trying to do something like this:
1
2
3
4
5
6
7
class
Deck {
private
: Card cards[52];
// ...
};
But this doesn't work. How am I supposed to create/call a class in a class then?
Thanks!
Sep 14, 2008 at 3:00am UTC
helios
(17607)
Does the definition of Card appear before the definition of Deck?
EDIT: v Hoho! Hive mind!
Last edited on
Sep 14, 2008 at 3:01am UTC
Sep 14, 2008 at 3:00am UTC
Duthomhas
(13282)
That should work just fine.
So long as Card is prototyped before Deck.
And if Card has a default constructor.
Hope this helps.
Sep 14, 2008 at 9:52pm UTC
slythfox
(2)
Thanks. I didn't realize order mattered. I would've assumed the compiler would've run through all the classes and add it to some sort of list that it would reference, then do the actual compiling...
Topic archived. No new replies allowed.