To better explain, I have the following constructor in class Card:
Card(std::string& s);
Therefore it only needs one string to create a Card object. However in another file where I have another class called Deck, which is derived from class Card, this class roughly looks like this:
deck.h:
class Deck : public Card
{
Card deck[52]; //this will hold 52 cards
};
deck.cpp:
Deck::Deck()
{
std::string value[13] = {"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"};
std::string suit[4] = {"H", "D", "C", "S"};
int k = 0;
for(int i = 0; i < 4; i++){
for(int j = 0; j < 13; j++){
//std::string str = value[j] + suit[i];
//deck[k] = str; //CREATES ALL 52 CARDS //<---INSTEAD OF DOING THIS
deck[k] = value[j] + suit[i]; //<---WHY CAN'T I SIMPLY DO THIS
k++;
}
}
}
Its just a simple question I am just curious as to why its so pedantic, because a sum of two strings is one string, so it should work.
Here is the error:
error: no match for ‘operator=’ (operand types are ‘Card’ and ‘std::basic_string<char>’)
deck[k] = value[j] + suit[i];