If I have a class with a private variable that's supposed to hold an array of pointers to another class, is the following syntax correct?
class MyClass
{
private:
int arraySize;
SomeOtherClass* classPtr[];
}
Later, when I want to dynamically allocate memory for this array in a function in MyClass that accepts an ifstream, reads from a file, and fills the array, would I do it like this?
void createArray(std::ifstream& fin)
{
//the first int is the array size
fin >> arraySize;
string tempString; //the file is formatted string int string int etc.
int tempInt;
classPtr[arraySize];
for(int i = 0; i < arraySize; i++)
{
fin >> tempString;
fin >> tempInt;
//assume the constructor is defined
classPtr[i] = new SomeOtherClass(tempString, tempInt);
}
Thanks for your time in advance.