【问题标题】:parameters sent don't match the function def发送的参数与函数 def 不匹配
【发布时间】:2015-10-23 12:25:45
【问题描述】:

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

呼叫:

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

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

函数定义:

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*)’

【问题讨论】:

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


【解决方案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*,这就是它在那里工作的原因,

【讨论】:

  • 感谢您的帮助解释。有一种方法可以通过 idstream 的构造函数转换为所需的类型。还是其他解决方案?
  • @cristian 将fn 更改为std::string 或者您可以将其转换为:stackoverflow.com/questions/4804298/…
猜你喜欢
  • 2021-07-24
  • 1970-01-01
  • 2021-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-10
相关资源
最近更新 更多