Hello
I'm trying to create a flash card program for my own personal use. Never mind the hows or whys, but I'm trying to create a couple of classes (card and deck) that have an array of strings to contain information fields about those objects.
Currently the constructor for my deck class looks like this:
Deck(string newField[STD_FIELD] = {""}, Card* newHeadDeck = NULL, Card* newTailDeck = NULL, Card* newHeadStdy = NULL, Card* newTailStdy = NULL);
obviously the only part I really care about is this:
string newField[STD_FIELD] = {""}
Because it keeps returning errors:
Expected primary-expression before "{" token |
Expected "," before "{" token |
Which I assume mean that it doesn't like using
{""}
to initialize all the fields in the array to empty.
I did it that way because I think you can initialize arrays of strings to empty using the same setup when you're creating them within a function, but how do you do the same thing for a default parameter within a constructor?
I know that push come to it I can just make the constructor empty the fields every time, and just make the user enter in new fields, but that seems inelegant to me and I feel like there's a better way to do it with default parameters.
Apologies for any formatting mistakes and newbish questions. I did my best to find out myself, but I'm afraid my old textbook only covers integer default parameters, and not things like strings or arrays (let alone arrays of strings).
Thanks for the help!