KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Consider this simple example: template <class Type> class smartref { public: smartref() : data(new Type) { } operator Type&(){ return *data; } private: Type* data; }; class person { public: void think() { std::cout << "I am thinking"; } }; int main() { smartref<person> p; p.think(); // why does not the compiler try substituting Type&? } How do conversion operators work in C++? (i.e) when does the compiler try substituting the type defined after the conversion operator?
Tags (comma-separated)
Save Edits
Cancel