There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen blue screen of death boot computer connection crash css dell display driver drivers email error ethernet excel firefox firefox 3 hard drive internet internet explorer itunes laptop malware monitor network networking outlook outlook 2003 outlook express partition password printer problem problems ram router security slow sound startup trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Default/Copy Constructor


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
jdjb78's Avatar
Member with 45 posts.
 
Join Date: Oct 2004
Location: Missouri
Experience: Advanced
14-Dec-2004, 09:40 PM #1
Default/Copy Constructor
Hi I need Help in C++ making a default and copy constructor for these classes.


Class Deck
{
Card cards [52];
}

Class Card
{
private:
int value;
int suit;
public:
void getvalue();
void getsuit();
}

Can you help me...
Thanks!
Jeremy

P.S. If you have any other questions...I can answer them
Regicide's Avatar
Senior Member with 302 posts.
 
Join Date: Aug 2003
Experience: Advanced
14-Dec-2004, 10:29 PM #2
The default constructor is something like this:
Code:
Card(arguments)
{
   ...
   ...
   ...
}
Notice, no return type. It can have arguments and if it does you initalize a new instance as such:
Code:
Card card(arg1, arg2)
THe copy contructor looks something like this:
Code:
Card(Card& card)
{
   ...
   ...
   ...
}
That is the only argument that the copy constructor can have. Finally, both the copy constructor and the default constructor must be declared as public in the class. Hope this helps.
__________________
When you give everything and the feeling is gone
All the giving is fake, did you fake enough?
When you take everything and you stay too long
When there's nothing left, did you take enough?
jdjb78's Avatar
Member with 45 posts.
 
Join Date: Oct 2004
Location: Missouri
Experience: Advanced
14-Dec-2004, 11:12 PM #3
Yeah i understand this....but im having problems figuring out what goes inside...I'm supposed to make a blackjack game. I know i need to have a card class, a deck class, a player class, and a house class. but i am not sure what to put inside them, and i dont know wht to put in the definitions of the default and copy constructors.

Jeremy
Regicide's Avatar
Senior Member with 302 posts.
 
Join Date: Aug 2003
Experience: Advanced
15-Dec-2004, 11:55 AM #4
From my understanding it looks like you will need only a constructor for the deck class. Therefore, inside of the deck constructor have a while or for loop to assgin a suit and value to each card. This is how I would do it:
Code:
#define SPADE 1
#define CLUB 2
#define HEART 3
#define DIAMOND 4
Deck()
{
   int n_card = 0;
   int n_value = 2;
   while(n_card < 13) {
      cards[n_card].value = n_value;
      cards[n_card].suit = SPADE;
      n_card++;
      n_value++;
   }
   ...
   ...
}
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:13 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.