I get an error " undefined reference to 'Card::Card()' ", when I try to compile. This program is supposed to print all cards in a deck after I initialize each one. It has to use OOP so I don't need that changed. Help anyone!
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
class Card
{
private:
string suit;
string value;
public:
Card();
Card(string a, string b)
{
suit = a;
value = b;
}
string getSuit()
{
return suit;
}
string getValue()
{
return value;
}
void print()
{
cout << getSuit() << " of " << getValue() << endl;
}
};
int main()
{
Card cardlist[52];
cardlist[0] = Card("2","Spades");
cardlist[1] = Card("3","Spades");
cardlist[2] = Card("4","Spades");
cardlist[3] = Card("5","Spades");
cardlist[4] = Card("6","Spades");
cardlist[5] = Card("7","Spades");
cardlist[6] = Card("8","Spades");
cardlist[7] = Card("9","Spades");
cardlist[8] = Card("10","Spades");
cardlist[9] = Card("Jack","Spades");
cardlist[10] = Card("Queen","Spades");
cardlist[11] = Card("King","Spades");
cardlist[12] = Card("Ace","Spades");
cardlist[13] = Card("2","Hearts");
cardlist[14] = Card("3","Hearts");
cardlist[15] = Card("4","Hearts");
cardlist[16] = Card("5","Hearts");
cardlist[17] = Card("6","Hearts");
cardlist[18] = Card("7","Hearts");
cardlist[19] = Card("8","Hearts");
cardlist[20] = Card("9","Hearts");
cardlist[21] = Card("10","Hearts");
cardlist[22] = Card("Jack","Hearts");
cardlist[23] = Card("Queen","Hearts");
cardlist[24] = Card("King","Hearts");
cardlist[25] = Card("Ace","Hearts");
cardlist[26] = Card("2","Diamonds");
cardlist[27] = Card("3","Diamonds");
cardlist[28] = Card("4","Diamonds");
cardlist[29] = Card("5","Diamonds");
cardlist[30] = Card("6","Diamonds");
cardlist[31] = Card("7","Diamonds");
cardlist[32] = Card("8","Diamonds");
cardlist[33] = Card("9","Diamonds");
cardlist[34] = Card("10","Diamonds");
cardlist[35] = Card("Jack","Diamonds");
cardlist[36] = Card("Queen","Diamonds");
cardlist[37] = Card("King","Diamonds");
cardlist[38] = Card("Ace","Diamonds");
cardlist[39] = Card("2","Clubs");
cardlist[40] = Card("3","Clubs");
cardlist[41] = Card("4","Clubs");
cardlist[42] = Card("5","Clubs");
cardlist[43] = Card("6","Clubs");
cardlist[44] = Card("7","Clubs");
cardlist[45] = Card("8","Clubs");
cardlist[46] = Card("9","Clubs");
cardlist[47] = Card("10","Clubs");
cardlist[48] = Card("Jack","Clubs");
cardlist[49] = Card("Queen","Clubs");
cardlist[50] = Card("King","Clubs");
cardlist[51] = Card("Ace","Clubs");
for (int i = 0; i < 52; i++)
cardlist[i].print();
return 0;
}
See Question&Answers more detail:
os