mardi 22 septembre 2015

Initialization in constructor - c++ dynamic allocation of string array

I've made a class, StringSet, for a dynamically allocated array of strings. My debugger tells me I have a problem with the default constructor (Create a dynamic array of strings, max size 4, current size 0) of my .cpp file,

StringSet::StringSet() : maxSize{4}, currSize{0}, arr{new string[maxSize]}  
{ 
}

My private member variables for StringSet consist of

int currSize;
int maxSize;
string* arr; // Ptr to a string; point to an array of dynamically allocated strings

the error reads: cannot convert ‘< brace-enclosed initializer list >’ to ‘int*’ in initialization. Why is there a problem associated with converting to type int when I've declared type string in both the .cpp constructor and the private member variable for the array?

Is my constructor not of the proper format to create the object array?

Aucun commentaire:

Enregistrer un commentaire