【问题标题】:Method requires more than one argument?方法需要多个参数?
【发布时间】:2013-02-09 20:21:08
【问题描述】:

所以,我不能像这样编译我的代码:

std::vector<std::string> split = split("A String Blah");  

使用此方法签名:

std::vector<std::string> split(const std::string& s)  

因为它说它需要多个参数。为什么仅仅一个字符串还不够?

【问题讨论】:

  • 确切的错误信息是什么?
  • Error 1 error C2660: 'split' : function does not take 1 arguments c:\users\aidan\documents\visual studio 2012\projects\mathhelper\mathhelper\mathhelper.cpp 59 1 MathHelper跨度>
  • 是您认为您从 MathHelper 库调用的 split
  • 您是否尝试调用函数之前创建了函数原型?
  • 问题是我更新方法签名时忘记更新原型了。谢谢@JoachimPileborg!

标签: c++ methods arguments signature


【解决方案1】:

当你有这条线时:

std::vector<std::string> split = split("A String Blah"); 

C++ 编译器认为右侧引用的split 与左侧声明的split 相同。结果,它给了你一个错误,因为事实上,std::vector&lt;std::string&gt; 不是一个接受一个参数的函数。

要解决此问题,请考虑重命名变量:

std::vector<std::string> theSplit = split("A String Blah"); 

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多