I have created a class called "letter":
class Letter
{
char letter{};
bool guessed{ false };
public:
void setLetter(std::string);
};
and I would like to create an array of class "Letter". The size of the array should be the size of a user inputted string, and if possible, each letter of the string should be stored in 1 element of the letter object. I have tried the following:
std::string word;
Letter test[] = word;
"initialization with {...} expected for aggregate object"
std::string word;
Letter test[word.length()]; // and then iterate through each element of the string
"expression must have a constant value"
EDIT: Solved
std::string word;
std::vector<Letter> test;
for (int i = 0; i < word.length(); i++)
{
test[i].setLetter(word[i]);
}
std::vectorwhen you need a dynamically sized array.vector?setLetter(std::string)should probably besetLetter(char);lettermember isprivate. PresumablysetLetteris responsible for setting it. But it takes a wholestd::stringinstead of just a letter. It isn't clear how it is intended to work, I can't imagine what it is supposed to do if the input is not exactly 1 letter. Did you mean to usevoid setLetter(char)instead?