发送的参数不匹配函数def

时间:2015-10-23 12:25:45

标签: c++ visual-c++ gcc

我有以下场景适用于Visual C ++ 10但不适用于Linux上的GCC:

呼叫:

value& v;
wstring fn(L"");
char_conv::str_to_wstr( path, fn );

parse( v, ifstream( fn.c_str() ) ); //<-- ERROR

功能def:

inline std::string parse(value& out, std::istream& is){...}

这是我得到的错误:

In member function ‘std::string PrintInvoker::extractParameter(const std::string&, picojson::value&)’:
error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const wchar_t*)’

1 个答案:

答案 0 :(得分:1)

std::idstream具有以下构造函数:

basic_ifstream();
explicit basic_ifstream( const char* filename,
            ios_base::openmode mode = ios_base::in );

explicit basic_ifstream( const string& filename,                                  
            ios_base::openmode mode = ios_base::in );

basic_ifstream( basic_ifstream&& other );

basic_ifstream( const basic_ifstream& rhs) = delete;

现在当您致电fn.c_str()时返回wchar_t*,因为fnwstrgin。正如您所看到的,没有重载需要wchar_t*,因此编译器会给您一个错误。

查看我的MSVS2015副本,似乎微软已经添加了一个确实占用wchar_t*的构造函数,这就是它在那里工作的原因,

相关问题