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. return 0;
  15. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:13: error: invalid initialization of non-const reference of type ‘Foo&’ from a temporary of type ‘const char*’
prog.cpp:7: error: in passing argument 1 of ‘void InitMethod(Foo&)’
stdout
Standard output is empty