mercredi 28 janvier 2015

cast to string operator overloading in C++

I am working on a class that has a method with the following signature:



operator const std::string & () const


It's documented as "cast to string operator". I am wondering how to effectively invoke it. Unfortunately the following expression:



std::string(foo)


produces this error:



some_test.cpp:13:41: error: no matching function for call to'
std::basic_string<char>::basic_string(Foo (&)(std::string))'


Considering that foo is of type Foo, declared and instantiated as Foo foo(std::string(filename))


being a begginner of C++, this leaves me a bit confused. Any hints on what this means?


Aucun commentaire:

Enregistrer un commentaire