fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Test {
  5. public:
  6. Test(const string& x) { //<<<<<<<<<<<<<<<<<< TRY WITH AND WITHOUT EXPLICIT
  7. cout<<"Conversion constructor called"<<endl;
  8. }
  9. };
  10.  
  11. // Two overloaded functions:
  12. void f(Test t) {
  13. cout<<"Function called for a Test"<<endl;
  14. }
  15. void f(string &s){
  16. cout<<"Function called for a string"<<endl;
  17. }
  18.  
  19. // demo
  20. int main() {
  21. string hello="Hello";
  22. const string world="World";
  23. f(hello);
  24. f(world); //<<<<<<<<<<< would you expect the string version to be called?
  25. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Function called for a string
Conversion constructor called
Function called for a Test