fork(3) download
  1. #include <iostream>
  2.  
  3. class A
  4. {
  5. public:
  6. class Key
  7. {
  8. Key() {}
  9. Key(Key const &) {}
  10. };
  11.  
  12. A(Key key, int a = 5) {}
  13. };
  14.  
  15. int main() {
  16. A a(A::Key()); // this compiles !!!
  17. A a2(A::Key(), 5); // this doesn't
  18. // somehow defaulting the argument causes the private constructor
  19. // to be OK - no idea why
  20. return 0;
  21. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:17:14: error: ‘A::Key::Key()’ is private within this context
  A a2(A::Key(), 5); // this doesn't
              ^
prog.cpp:8:3: note: declared private here
   Key() {}
   ^~~
prog.cpp:17:18: error: ‘A::Key::Key(const A::Key&)’ is private within this context
  A a2(A::Key(), 5); // this doesn't
                  ^
prog.cpp:9:3: note: declared private here
   Key(Key const &) {}
   ^~~
prog.cpp:12:2: note:   initializing argument 1 of ‘A::A(A::Key, int)’
  A(Key key, int a = 5) {}
  ^
stdout
Standard output is empty