Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A;
- class Lock {
- friend class A; //have friendship here, so that A can access private Lock() {} in initializing
- //but in class B, Lock() is not accessable
- private:
- Lock() {};
- };
- class A: virtual public Lock { //virtual public is used, so that A can not be inherited
- //virtual public is used, so base class (class Lock)'s initialization would be depolyed
- //if class Lock { private:Lock() {}}; is commented, this would be ok
- public:
- A() {};
- A(int n) {};
- };
- class B: public A { //Point is that Lock作为虚基类;在继承体系中B是最远派生类,初始化时候要负责调用Lock的初始化函数,但是Lock::Lock()是private,所以无法被调用
- public:
- B() {};
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement