previous | start | next

13. New and Class Types

Class types can be used with new. But just as with declarations, a constructor must be used so that the class value that new creates is properly initialized.:

 Car *p;
 Car *r;

 p = new Car(20);
 r = new Car(); // or new Car;

 p->drive(100);
 r->addGas(16);

         


previous | start | next