fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<class C>
  5. class Bar
  6. {
  7. public:
  8. Bar(C& c) : _c(c) {};
  9. ~Bar(){};
  10.  
  11. private:
  12. C& _c;
  13. };
  14.  
  15. class Foo
  16. {
  17. public:
  18. Foo() : bar(this) {}; //instead of bar(*this)
  19. ~Foo(){};
  20.  
  21. private:
  22. Bar<Foo> bar;
  23. };
  24.  
  25.  
  26. int main() {
  27. // your code goes here
  28. Foo f;
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 3136KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor 'Foo::Foo()':
prog.cpp:18:19: error: no matching function for call to 'Bar<Foo>::Bar(Foo*)'
   Foo() : bar(this) {};
                   ^
prog.cpp:18:19: note: candidates are:
prog.cpp:8:3: note: Bar<C>::Bar(C&) [with C = Foo]
   Bar(C& c) : _c(c) {};
   ^
prog.cpp:8:3: note:   no known conversion for argument 1 from 'Foo*' to 'Foo&'
prog.cpp:5:7: note: Bar<Foo>::Bar(const Bar<Foo>&)
 class Bar
       ^
prog.cpp:5:7: note:   no known conversion for argument 1 from 'Foo*' to 'const Bar<Foo>&'
stdout
Standard output is empty