| | |
How do I get classes within a class???
![]() |
For instance... I have the class Deck, which represents a deck of cards, and I want another class, derived from that, called cards, I want class Deck to have a class array called Cards[52], so I can assign all the different values and strings to the individual Cards class instances and have the class Deck do things to the deck as a whole... Im talkin something like this
ik that you might not understand why i want to do this in two different classes, but i do... so please just gimme a clear cut answer. please and thank you!
C++ Syntax (Toggle Plain Text)
class Deck{ protected: class Cards[52]; // This doesnt work to have multiple instances in the class public: void Shuffle(); }; class Cards : public Deck{ Cards(int,string); };
ik that you might not understand why i want to do this in two different classes, but i do... so please just gimme a clear cut answer. please and thank you!
Don't define class Card within class Deck.
Create a card class.
Then let deck class contain an array of card objects
class Card {
string suit;
int value;
///more stuff
};
class Deck{
Card theDeck[52];
//more stuff
};
Create a card class.
Then let deck class contain an array of card objects
class Card {
string suit;
int value;
///more stuff
};
class Deck{
Card theDeck[52];
//more stuff
};
Don't own a gun but I'm going to join the NRA.
I figure anything that irritates liberals is worth my support.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
I figure anything that irritates liberals is worth my support.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Apr 2008
Posts: 187
Reputation:
Solved Threads: 10
When I had to use two classes that interlaced, I wrote my first class out, then wrote the second class out, then had a variable in the second class that called the first class. For your example, I would write out what you want class Card to do. Then write out what you want class Deck to do, and when you know where they overlap, use a variable that jumps between the classes.
For me, I'm going to call my classes Deck and PCards so I can make sure it all makes sense. So, say you want class Deck to shuffle the cards. You would try something like this:
Where they would be a function in class PCards that would randomize them. Now, that's just off the top of my head, and I don't know what you are trying to do, but that's how I handled having two classes.
For me, I'm going to call my classes Deck and PCards so I can make sure it all makes sense. So, say you want class Deck to shuffle the cards. You would try something like this:
C++ Syntax (Toggle Plain Text)
PCards Shuffle (PCards cards[], int 52) { cards.randomize(); return cards; }
Where they would be a function in class PCards that would randomize them. Now, that's just off the top of my head, and I don't know what you are trying to do, but that's how I handled having two classes.
![]() |
Similar Threads
- Help on Creating Class in VB6 (Visual Basic 4 / 5 / 6)
- Creating special classes (Java)
- Visual Basic "Classes" and "Class Modules" (Visual Basic 4 / 5 / 6)
- class diagram/uml (Java)
- C++ Classes (C++)
- Design and Implement a class hierarchy for an organization/university (C)
- Class Constructor Shorthand (C++)
- Which type of class is not instantiated? (Java)
- Working with objects of different Classes (Java)
Other Threads in the C++ Forum
- Previous Thread: Creating a c++ program
- Next Thread: What is wrong with the following class definition?
Views: 322 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary browser c++ c++borland c/c++ calculator char class classes code compile compiler console constructor conversion convert count delete display dll dynamic encryption error file files fstream function functions game givemetehcodez graph gui helpwithhomework homework i/o iamthwee input int java lazy lib library linker list loop loops math matrix memory newbie news number numbers object objects opengl output pointer pointers problem program programming project qt random read reading recursion recursive reference return sort sorting spoonfeeding string strings struct student studio template templates text time tree variable vc++ vector video visual visualstudio win32 window windows winsock






