fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. protected:
  6. A() {cout << "A()" << endl;};
  7. };
  8.  
  9. class B : protected A {
  10. public:
  11. static const B& get() {
  12. static B instance;
  13. return instance;
  14. }
  15. protected:
  16. B():A() { cout << "B()" << endl;};
  17. };
  18.  
  19. int main() {
  20. // your code goes here
  21. // A a; won't compile
  22. // B b; won't compile too
  23. B::get();
  24. return 0;
  25. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
A()
B()