Cast Operator with template class

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 ?

Answers


_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.


Need Your Help

Delete woocommerce customer sessions and transients automatically

wordpress woocommerce

One of my client's site was slowed down too much and its waiting time was 6 to 7 seconds. I found the root cause which was because the wp_options table was filled with a lot of customer sessions data

Horizontal vs Vertical Fragmentation in Distributed Database Management Systems (DDBMS)

database distributed fragmentation

In the context in DDBMS, what is the difference between Vertical Fragmentation and Horizontal Fragmentation?