GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Jun-2006, 13:38
verticalvoid verticalvoid is offline
New Member
 
Join Date: Jun 2006
Posts: 2
verticalvoid is on a distinguished road

Card class help


Hello,

I've just begun working on a side project of mine, and I can't get much farther. I'm working on creating a card class (which is complete), and a working deck class to match which uses the card class. However, the problem seems to be with the enumerated types I have for the suit and rank of the card. It appears as if the Deck class can't recognize the enumerated types embedded in the Card class. Here's the header file for my Card class.

CPP / C++ / C Code:

// a class for cards
#ifndef CARD_H
#define CARD_H
#include <vector>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

class Card{

 public:
  enum Rank{ACE, TWO, THREE, FOUR,
	    FIVE, SIX, SEVEN, EIGHT,
	    NINE, TEN, JACK, QUEEN, KING};
  enum Suit{SPADES, HEARTS, DIAMONDS, CLUBS};
  
  // Constructors

  // default
  Card();
  // most common
  Card(Rank newrank, Suit newsuit);
  // copy constructor

  Card(const Card & C);
  // mutators
  
  void SetRank(Rank newrank){
    rank = newrank;
    TheString = GetString();
  }
  void SetSuit(Suit newsuit){
    suit = newsuit;
    TheString = GetString();
  }
  // inspectors
  
  Rank GetRank(){
    return rank;
  }
  Suit GetSuit(){
    return suit;
  }
  string GetString();
  
   
 private:
  Rank rank;
  Suit suit;
  string TheString;
};

#endif


Now, like I said, the error seems to be with the enumerated types. Here's the following code for the beginning of my deck.cpp class.

CPP / C++ / C Code:

#include "deck.h"

Deck::Deck(int x){ 
  resize(52 * x);  
  for (int i = 0; i < size(); i++){    
    Card Current;
    switch(i % 13){
    case 0:
      Current.SetRank(ACE);
      break;
    case 1:
      Current.SetRank(TWO);
      break;
    case 2:
      Current.SetRank(THREE);
      break;
    case 3:
      Current.SetRank(FOUR);
      break;
    case 4:
      Current.SetRank(FIVE);
      break;
    case 5:
      Current.SetRank(SIX);
      break;
    case 6:
      Current.SetRank(SEVEN);
      break;
    case 7:
      Current.SetRank(EIGHT);
      break;
    case 8:
      Current.SetRank(NINE);
      break;
    case 9:
      Current.SetRank(TEN);
      break;
    case 10:
      Current.SetRank(JACK);
      break;
    case 11:
      Current.SetRank(QUEEN);
      break;  
    case 12:
      Current.SetRank(KING);
      break;
    }
    
    switch(i % 4){
    case 0:
      Current.SetSuit(SPADES);
      break;
    case 1:
      Current.SetSuit(HEARTS);
      break;
    case 2:
      Current.SetSuit(DIAMONDS);
      break;
    case 3:
      Current.SetSuit(CLUBS);
      break;
    }
    
    this[i]=Current;
  }
}


I get an error message saying basically saying that all my enumerated types are undeclared. I never really learned exactly how enumerated types worked in C++, so I keep on emphasizing that this is the problem.

Oh, in addition, the deck class is inherited from a vector of cards, and I'm writing my deck class to be able to handle multiple decks shuffled together. Any help or insight into this problem would be nice.

Thanks,
Matt
  #2  
Old 29-Jun-2006, 21:29
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough

Re: Card class help


have you tried referring to the enumerated type as Card::TWO, Card::THREE, etc?
  #3  
Old 29-Jun-2006, 21:51
verticalvoid verticalvoid is offline
New Member
 
Join Date: Jun 2006
Posts: 2
verticalvoid is on a distinguished road

Re: Card class help


Ha,

Actually, I managed to do just that a couple of hours ago. Funny how that works. Should've left a post mentioning I figured the problem.

Now my problem is pointers. It's been years since I've done that. Bogging through, about got it though. Yippee. A day of programming and I about got my project done. Whoo..

Thanks again for posting,
Matt
 
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
a tester class and then some. postage Java Forum 1 06-May-2006 15:48
Opinion on my code and a c++ class question FlipNode CPP / C++ Forum 7 07-Feb-2006 08:15
Need Help with my Cards Program (C++) krisopotamus CPP / C++ Forum 2 06-Oct-2005 16:48
Error C2146: syntax error : missing ',' before identifier 'C4' mattchew008 CPP / C++ Forum 2 19-Dec-2004 06:06
can't solve the sum ryz CPP / C++ Forum 0 30-Oct-2003 18:55

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:18.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.