Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. class A;
  2.  
  3. class Lock {
  4. friend class A; //have friendship here, so that A can access private Lock() {} in initializing
  5. //but in class B, Lock() is not accessable
  6. private:
  7. Lock() {};
  8. };
  9.  
  10. class A: virtual public Lock { //virtual public is used, so that A can not be inherited
  11. //virtual public is used, so base class (class Lock)'s initialization would be depolyed
  12. //if class Lock { private:Lock() {}}; is commented, this would be ok
  13. public:
  14. A() {};
  15. A(int n) {};
  16. };
  17.  
  18. class B: public A { //Point is that Lock作为虚基类;在继承体系中B是最远派生类,初始化时候要负责调用Lock的初始化函数,但是Lock::Lock()是private,所以无法被调用
  19. public:
  20. B() {};
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement