fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Outer {
  5. struct Inner {
  6. int num;
  7. };
  8.  
  9. public:
  10. static Inner GetInner() {
  11. return Inner{-101};
  12. }
  13. };
  14.  
  15. // void func1(Outer::Inner inner) { // [1] Does not compile as expected
  16. // cout << inner.num <<endl;
  17. //}
  18.  
  19. template <typename Dummy>
  20. void func2(Outer::Inner inner, Dummy = Dummy()) {
  21. cout << inner.num << endl;
  22. }
  23.  
  24.  
  25. int main() {
  26. // func1(Outer::GetInner()); // [2] does not compile as expected
  27. func2<int>(Outer::GetInner()); // [3] How does this compile?
  28. // Outer::Inner should not be accessible
  29. // from outside Outer
  30. return 0;
  31. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
-101