I am trying to allocate memory for an array of unknown size that is a datamember of a class.
The datamember is:
PassengerCompartment** pass_comp;
In the copy constructor of the class (Plane) that I want to allocate the array, I have this:
(“given” is a const Plane&)
pass_comp = new PassengerCompartment*[given.NOofAlloc_PasCom];
for (int i=0; i < NOofAlloc_PasCom; i++)
{
pass_comp = new PassengerCompartment( given.(*pass_comp[i]) );
}
And I am getting this compiler error:
error: expected unqualified-id before ‘(’ token
at this line:
pass_comp = new PassengerCompartment( given.(*pass_comp[i]) );
( the “(” that is mentioned, is the 1st one, after PassengerCompartment)
What have I done wrong?
Thank you for your time!
It is surely not the first bracket, but the second, as
given.(*pass_comp[i])is not valid syntax. Maybe you meant*given.pass_comp[i](which dereferencesgiven.pass_comp[i])?Oh, and you probably also want
pass_comp[i]instead ofpass_compbefore the assignment operator.