简体   繁体   中英

Clang error, no viable conversion

I am facing an issue with clang 3.1. This particular issue does not arise with GCC 4.2. The following is an example of the error that occurs:

#include <stdio.h>
#include <iostream>
#include <sstream>
#include <string>

typedef unsigned short char16_t;
typedef char16_t TCHAR;

typedef std::basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR> > wstringT;

template<class T>
inline wstringT MyTestFunction(const T& source)
{
std::wstringstream out;
out << source ;
return out.str();    // error occurs here
};

The error message states:

No viable conversion from '__string_type' (aka 'basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >') to 'wstringT' (aka 'basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR> >')

The code is compiled with the compiler flag -fshort-wchar, which is supposed to convert wchar_t to a 16 bit unsigned short. I am compiling the code on XCode v4.3.2.

如果你想使用TCHAR你必须扩展每个模板以使用它,包括你真正想要basic_stringstream<TCHAR> wstringstream ,或者你可以:

typedef std::basic_stringstream<TCHAR> tstringstream;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM