Tuesday, February 26, 2013

C++ revisited

1. const and reference members may only be initialized, never assigned.

2. list members in an initialization list in order in which they are declared.
- static data members are initialized only once.
- base class data members are initialized before derived class data members.
-virtual destructor must be defined

3. ps1->Shape::draw();   //explicitly call base function

4. a summary of public/private inheritance and friend:

- public and private inheritance can access public and protected members of base class;
- public and private inheritance cant access private members of base class;
- an instance of derived class
           --public inheritance can access public members of base class
           --private inheritance cannot access public members of base class

class B
{
friend class A;
friend B operator+(B b1, B b2);
}

A can access private members of B;
+ can access private members of B;

No comments:

Post a Comment