For c++, using visual studio command prompt (2010) as compiler, notepad++ as editor
I'm having such a specific issue I can't seem to find the answer I'm looking for in searches so here goes:
Regarding a program assignment with some constraints (I cant use different variable).
I have a class Card with a static constant member array called "faceName" in my untouchable header file.
I am initializing this member array in my implementation file with assignment operator and list of string literals.
Instead of the boring text "Spades" and "Hearts" etc for suit names, I want to use the char ascii codes 3,4,5, and 6 for the actual symbols.
I can't figure out how to typecast my char variables into something the string can read then load them into the string all in a single line (Since a constant can't be modified later, and I can't actually do the char creation in main, and must be done loosely floating in the implementation file.
Been years since I've programmed, sorry for my poor vocabulary usage if I stated anything incorrectly.
Card.h
class Card
{
private:
int face;
int suit;
static const int NUM_OF_SUITS = 4;
static const int FACES_PER_SUIT = 13;
static const string suitName[NUM_OF_SUITS];
static const string faceName[FACES_PER_SUIT];
public:
string toString() const;
}
Card.cpp
const string Card::faceName[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}
const string Card::suitName[] = {(char)3, (char)4, (char)5, (char)6}
string Card::toString() const
{
string nameOfCard;
if (suit >= 0 && suit <= NUM_OF_SUITS && face >= 0 && face <= FACES_PER_SUIT)
{
nameOfCard = faceName[face] + " of " + suitName[suit];
}
else nameOfCard = "Error, card type doesn't exist.";
return nameOfCard;
}
and my error:
card.cpp(14) : error C2440: 'initializing' : cannot convert from 'char' to 'const std::string'
No constructor could take the source type, or constructor overload resolution was ambiguous
And I can't simply create an sstream to do the conversion because where would I do that? In main - too late, I need to initialize the member arrays in the implementation file.
Thanks for any help!