- Sep 15, 2005
- 3,622
- 1
- 0
I am trying to learn a bit of C++ coming from mostly languages like java, C# and flash
having trouble getting this code to compile
I get the following error
Building target: CardGame
Invoking: GCC C++ Linker
g++ -o"CardGame" ./src/Card.o ./src/CardGame.o
./src/Card.o: In function `Card::identifyCard()':
/home/bazookatooth/workspace/CardGame/Debug/../src/Card.cpp:39: undefined reference to `Card::CARD_RANKS'
my .cpp file
/*
* Card.cpp
*
* Created on: Aug 7, 2011
* Author: bazookatooth
*/
#include "Card.h"
using namespace std;
const string CARD_SUITS[4] = {"Clubs", "Diamonds", "Hearts", "Spades"};
const string CARD_RANKS[13] = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
Card::Card(int cardValP) {
cardValue = cardValP;
identifyCard();
}
//will be implemented
int Card::compareCards(Card card1P, Card card2P){
return 0;
}
void Card::identifyCard(){
int cardIdent = 52 - cardValue;
//find suit of card
if(cardIdent < 14)
cardSuit = "Clubs";
else if(cardIdent >= 14 && cardIdent < 27)
cardSuit = "Diamonds";
else if(cardIdent <= 27 && cardIdent < 40)
cardSuit = "Hearts";
else
cardSuit = "Spades";
//get name of card
cardName = CARD_RANKS[getCardValue() % 13];
}
int Card::getCardValue(){
return cardValue;
}
string Card::getCardName(){
return cardName;
}
string Card::getCardSuit(){
return cardSuit;
}
-----------
my .h file
/*
* Card.h
*
* Created on: Aug 7, 2011
* Author: bazookatooth
*/
#ifndef CARD_H_
#define CARD_H_
#include <string>
using namespace std;
class Card{
public:
Card(int); //card constructor
int compareCards(Card card1P, Card card2P); //compare two cards - used for card race so far
void identifyCard(); //give a card its suit and name
int getCardValue();
string getCardName();
string getCardSuit();
static const string CARD_SUITS[4];
static const string CARD_RANKS[13];
private:
int cardValue;
string cardSuit;
string cardName;
};
#endif /* CARD_H_ */
having trouble getting this code to compile
I get the following error
Building target: CardGame
Invoking: GCC C++ Linker
g++ -o"CardGame" ./src/Card.o ./src/CardGame.o
./src/Card.o: In function `Card::identifyCard()':
/home/bazookatooth/workspace/CardGame/Debug/../src/Card.cpp:39: undefined reference to `Card::CARD_RANKS'
my .cpp file
/*
* Card.cpp
*
* Created on: Aug 7, 2011
* Author: bazookatooth
*/
#include "Card.h"
using namespace std;
const string CARD_SUITS[4] = {"Clubs", "Diamonds", "Hearts", "Spades"};
const string CARD_RANKS[13] = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
Card::Card(int cardValP) {
cardValue = cardValP;
identifyCard();
}
//will be implemented
int Card::compareCards(Card card1P, Card card2P){
return 0;
}
void Card::identifyCard(){
int cardIdent = 52 - cardValue;
//find suit of card
if(cardIdent < 14)
cardSuit = "Clubs";
else if(cardIdent >= 14 && cardIdent < 27)
cardSuit = "Diamonds";
else if(cardIdent <= 27 && cardIdent < 40)
cardSuit = "Hearts";
else
cardSuit = "Spades";
//get name of card
cardName = CARD_RANKS[getCardValue() % 13];
}
int Card::getCardValue(){
return cardValue;
}
string Card::getCardName(){
return cardName;
}
string Card::getCardSuit(){
return cardSuit;
}
-----------
my .h file
/*
* Card.h
*
* Created on: Aug 7, 2011
* Author: bazookatooth
*/
#ifndef CARD_H_
#define CARD_H_
#include <string>
using namespace std;
class Card{
public:
Card(int); //card constructor
int compareCards(Card card1P, Card card2P); //compare two cards - used for card race so far
void identifyCard(); //give a card its suit and name
int getCardValue();
string getCardName();
string getCardSuit();
static const string CARD_SUITS[4];
static const string CARD_RANKS[13];
private:
int cardValue;
string cardSuit;
string cardName;
};
#endif /* CARD_H_ */
