May 7, 2015 at 10:56am UTC
If you just want to call the function right after you created the object you could store the pointer as a CruiseShip pointer while you call the functions.
1 2 3 4 5
CruiseShip* cruiseShip = new CruiseShip();
cruiseShip->showInfo();
cruiseShip->setName("The Tourist" );
cruiseShip->setPass(5000);
ship[1] = cruiseShip;
If you want to be able to call setPass on a Ship pointer you might want to make the function a (virtual?) member function of Ship.
Last edited on May 7, 2015 at 10:59am UTC
May 7, 2015 at 11:01am UTC
Thanks, the first soln meets my task
Last edited on May 7, 2015 at 11:01am UTC
May 7, 2015 at 11:12am UTC
One more thing, for the array should I just delete like
Ship ** ship= new Ship*[2];//what I defined
delete [] ship
or i delete in a loop?
Last edited on May 7, 2015 at 11:13am UTC
May 7, 2015 at 12:03pm UTC
You should use delete
on everything that you created using new
.