发送的参数与函数 def 不匹配

parameters sent don't match the function def

本文关键字:函数 def 不匹配 参数      更新时间:2023-10-16

我有以下场景,可在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*)’

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*因为fn是一个wstrgin。正如你所看到的,没有重载需要一个wchar_t*,所以编译器会给你一个错误。

看看我的MSVS2015副本,似乎微软已经添加了一个构造函数,确实需要一个wchar_t*,所以这就是为什么它在那里工作,