Jump to content
  • Advertisement
Sign in to follow this  
Tokiko

Help with class constructor

This topic is 5024 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
EDIT: Uhh...I deleted it, looks like Oluseyi was getting ready to delete it for being a "direct answer"...and I sorta agree with him.

Share this post


Link to post
Share on other sites
Aw, come on!

Read the documentation for LNK2001, then try your hand at the problem. I will delete any direct solutions given until you come back and report how you did. You have to at least try!

Share this post


Link to post
Share on other sites
Quote:
Original post by Boku San
EDIT: Uhh...I deleted it, looks like Oluseyi was getting ready to delete it for being a "direct answer"...and I sorta agree with him.
Thanks. [smile]

Share this post


Link to post
Share on other sites
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!