Chinese Yellow Pages | Classifieds | Knowledge | Tax | IME

For some C++ features, it is much easier to understand using sample code

virtual base class ( for multiple inheritance )

class A { public: A(int i); }
class B: virtual public A {}
class C: virtual public A {}

class D: public B, public C{ public:  D(int i):B(i),C(i), A(i){} }

notes:

A’s constructor will be ignored in B,C in this case
D is responsible for constructing the virtual base class A

template specialization

template<typename T> void sort(Array<T>& v)
template<> void sort<int>(Array<int>& v) // template specialization

Template Partial Specialization
template<typename T1, typename T2, int I> class A { };
template<typename T1, typename T2, int I> class A<T1*, T2, I> { }; // Partial Specialization

friends

class A {
private: int a;

public:
friend class B; // Friend Class
friend void getA(A&); // global friend function
};

class B {

void func(A& x) { // B can access private members of A
cout<< x.a
}
};

void getA(A& x) {
// getA can access private members of A
cout << x.a;
}

Leave a Reply

Your email address will not be published. Required fields are marked *