小编Eli*_*Eli的帖子

在Visual Studio 2005上使用TCHAR进行C++模板函数特化

我正在编写一个使用模板化运算符<< function的日志类.我专门研究宽字符串的模板函数,这样我就可以在写日志消息之前做一些从宽到窄的翻译.我不能让TCHAR正常工作 - 它不使用专业化.想法?

这是相关的代码:

// Log.h header
class Log
{
  public:
    template <typename T> Log& operator<<( const T& x );

    template <typename T> Log& operator<<( const T* x );

    template <typename T> Log& operator<<( const T*& x );

    ... 
}

template <typename T> Log& Log::operator<<( const T& input )
{ printf("ref"); }

template <typename T> Log& Log::operator<<( const T* input )
{ printf("ptr"); }

template <> Log& Log::operator<<( const std::wstring& input );
template <> Log& Log::operator<<( const wchar_t* input …
Run Code Online (Sandbox Code Playgroud)

c++ templates wchar-t widestring template-specialization

0
推荐指数
1
解决办法
935
查看次数