mardi 26 mai 2015

Here is the code:

class Foo { 
public:
    operator string() const { return n; }
    string n {"foo"};
};

and here is the usage:

string s {Foo{}};
cout << s << endl;

This code compiles using gcc 4.8.3, but it does not compile using clang 3.5, can someone tell me what's wrong with it?

I got an error like this:

main.cpp:45:12: error: no matching constructor for initialization of 'string' (aka 'basic_string<char>')
    string s {Foo{}};
           ^ ~~~~~~~

Thanks

Aucun commentaire:

Enregistrer un commentaire