class Foo{ public: Foo(const char* ){} friend void InitMethod(Foo& obj);};void InitMethod(Foo& obj){}int main(){ Foo myVar("InitMe"); InitMethod(myVar); //Works InitMethod("InitMe"); //Does not work return 0;}
Standard input is empty
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&)’
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!