Reputation: 1839
I want to overload a cast operator, I have the following piece of code :
template <typename _T>
class CTest
{
public :
_T data;
CTest(_T _data) : data(_data) {}
~CTest() {}
operator _T(){ return data; }
};
And MS Visual Studio 2005, give me the following errors :
warning C4003: not enough actual parameters for macro 'T' warning C4003: not enough actual parameters for macro '_T' error C2833: 'operator L' is not a recognized operator or type see reference to class template instantiation 'CTest<_T>' being compiled error C2059: syntax error : 'newline' error C2334: unexpected token(s) preceding '{'; skipping apparent function body error C2833: 'operator L' is not a recognized operator or type
How can I declare operator _T() correctly ?
Upvotes: 1
Views: 505
Reputation: 121971
_T
is a WINAPI macro (see Generic-Text Mappings in Tchar.h or Should I use _T or _TEXT on C++ string literals?): change _T
to T
.
Upvotes: 5