Sign in to follow this  
Tokiko

Help with class constructor

Recommended Posts

Tokiko    138
I was messing around with this code I got off msdn.microsoft.com and I tried compiling the example they provided, however I get an error report saying "[Linker error] undefined reference to `Card::Card(int, Card::Suit)'" Im guessing it has to do with constructing a new Card in the loop body. I don't know how to fix this, as I know little about classes. Here's the code.
class Card
{
public:
    enum Suit
    {
        Diamonds,
        Hearts,
        Clubs,
        Spades
    };

    // Declare two constructors: a default constructor,
    //  and a constructor that sets the cardinal and
    //  suit value of the new card.
    Card();
    Card( int CardInit, Suit SuitInit );

    // Get and Set functions.
    int   GetCardinal();        // Get cardinal value of card.
    int   SetCardinal();        // Set cardinal value of card.
    Suit  GetSuit();            // Get suit of card.
    void  SetSuit(Suit new_suit);  // Set suit of card.
    char *NameOf();             // Get string representation of card.
private:
    Suit  suit;
    int   cardinalValue;
};

// Define a postfix increment operator for Suit.
inline Card::Suit operator++( Card::Suit &rs, int )
{
    return rs = (Card::Suit)(rs + 1);
}

int main()
{
    Card *Deck[52];
    
    int   j = 0;

    for( Card::Suit curSuit = Card::Diamonds; curSuit <=    Card::Spades;
      curSuit++ )
          for( int i = 1; i <= 13; ++i )
              Deck[j++] = new Card( i, curSuit );
    
return 0;
} 


Thanks for any help.

Share this post


Link to post
Share on other sites
Tokiko    138
Lol, im soo tired and I can't think. It's probably so simple and yet I can't think of it. Im downloading the docs right now and I'll give it a look through.

Share this post


Link to post
Share on other sites
Tokiko    138
I feel like an idiot now that I still haven't found the problem after reading the doc and checking the code over. Perhaps, i'll try tomorrow. Damn this is getting on my nerves now, all thanks to you Oluseyi! lol

Share this post


Link to post
Share on other sites
Boku San    428
I would recommend getting a good book on C++. Or even C. Or even Java.

Hell, even BASIC. This is a very, very simple problem, and I think you're just messing with us, or you just got off the boat. The intergalactic boat. From somewhere OUTSIDE the Milky Way.

Since I can't answer directly, I'll say that a declaration inside a function is very, very similar to a function declaration globally. In fact, it's more-or-less the same thing.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Lol, I can't believe I missed that! My brain just blacked out. And Boku san im reading accelerated c++, so don't think im some dumb noob, because it was just a simple error that I missed. It happens.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this