Constructor:
const string & s
The
& means that the argument is passed by reference, not by value. Doing so you avoid to copy the object passes.
const means that even if the argument is passed by reference, it can't be modified in the function
: shapeType( s )
this is the initializer list, the class members are initialized with the value given (in this case
shapeType is initialized with the value of
s (the constructor argument
const string & getType( ) const
const string &
The return type is a const reference of a string (same meaning of the argument in the constructor but in this case is the return type)
getType( ) const
const means that the function doesn't modify the class instance (so it can be called for variable of type
const Shape
)
virtual double getArea( ) const = 0;
virtual
means that the function can have overrides (different bodies) on derived class
const
is same as above
= 0;
means that the virtual function hasn't the body in the base class, this makes the class abstract and it can't have objects
virtual void print( ostream & out ) const
Everything is as was for the function except for the fact that this has the body in the base class
ostream & out
streams don't have the copy constructor so they must be passed by reference
In classes all members are visible not depending in which order they were declared
Some documentation:
http://www.cplusplus.com/doc/tutorial/functions2.html
http://www.cplusplus.com/doc/tutorial/polymorphism.html
[Edit] Many answers at the same time...