fork download
  1. class Foo
  2. {
  3. public:
  4. Foo(const char* ){}
  5. friend void InitMethod(Foo& obj);
  6. };
  7. void InitMethod(Foo& obj){}
  8. int main()
  9. {
  10. Foo myVar("InitMe");
  11. InitMethod(myVar); //Works
  12.  
  13. //InitMethod("InitMe"); //Does not work
  14.  
  15. InitMethod(Foo("init"));
  16.  
  17. return 0;
  18. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:15: error: invalid initialization of non-const reference of type ‘Foo&’ from a temporary of type ‘Foo’
prog.cpp:7: error: in passing argument 1 of ‘void InitMethod(Foo&)’
stdout

Standard output is empty