I want to allocate an array of C++ objects using the following code:
class myClass {
public:
myClass(int userValue)
: value(userValue)
{ }
}
private:
int value;
};
int main(){
myClass* objArray = new myClass(22)[5];
return 0;
}
But it gives me the following error:
In constructor ‘myClass::myClass(int32)’:
error: expected ‘;’ before ‘[’ token
objArray = new objArray(22)[5];
How should I create an array of objects then while passing parameters to them?