4

clang3.1で問題が発生しています。この特定の問題は、GCC4.2では発生しません。発生するエラーの例を次に示します。

#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
};

エラーメッセージには次のように記載されています。

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> >')

コードはコンパイラフラグ-fshort-wcharを使用してコンパイルされます。これは、wchar_tを16ビットのunsignedshortに変換することになっています。XCodev4.3.2でコードをコンパイルしています。

4

1 に答える 1

3

使用したい場合は、実際に必要なTCHARものを含め、すべてのテンプレートを拡張して使用する必要があります。wstringstreambasic_stringstream<TCHAR>

typedef std::basic_stringstream<TCHAR> tstringstream;
于 2012-10-18T13:32:17.960 に答える