C++ classes
•The C++ class keyword permits to describe the common layout (data members) and interface (allowed operations) of every object instance which belongs to a data type that the user is modeling. •After having declared a class of objects which share the same internal representation and the same allowed operations (member functions) as many instances of this new data type can be created as you like
•
http://www.alessandroogheri.com
For example, the programmer could model a car object this way:
class car {
engine motor;
public: //please ignore for the moment
void on();
void off();
};
This means that a car object is something that has an engine, represented by the motor data member, and for which two operations are permitted: on() (which presumably turns the engine on) and off() (which turns the engine off).
After having given these lines, the user could create more instances of the car class, with statements like:
car renault_megane, fiat_punto,opel_astra;
and operate on them with the allowed member functions:
renault_megane.on();
opel_astra.off();
Please be aware that, while every instance of the car class shown permits the same operations on it (namely, on() and off()) they have each one their own copy of the data members, i.e. the renault_megane and the fiat_punto objects for example have their own motor inside!