错误:对的调用没有匹配的函数调用-使用VS2013编译
error: no matching function call for call to - compiles with VS2013 though
我正在编写一段应该在多个平台上运行的代码。我在使用Visual Studio 2013进行编译时,代码正常工作,没有任何问题,但现在我尝试为Android进行编译,我收到了标题中提到的错误。
我试图编译的代码是这样的:
#pragma once
#include <string>
class StringUtils
{
public:
static std::string readFile(const std::string& filename);
static std::string& trimStart(std::string& s);
static std::string& trimEnd(std::string& s);
static std::string& trim(std::string& s);
};
错误中提到了上述方法。举个例子,我试着这样调用trim()
方法:
std::string TRData::readValue(std::ifstream& ifs)
{
std::string line;
std::getline(ifs, line);
int colon = line.find_first_of(':');
assert(colon != std::string::npos);
return StringUtils::trim(line.substr(colon + 1));
}
错误消息指向此方法中的最后一行。如何解决此问题?正如我所说,它使用VS2013进行编译,但不适用于使用默认NDK工具链的Android。
编辑:忘记粘贴准确的错误消息,在这里:
error : no matching function for call to 'StringUtils::trim(std::basic_string<char>)'
您需要将函数签名更改为
static std::string& trim(const std::string& s);
// ^^^^^
将右值(如从substr()
返回的临时值)传递给函数。
同样,仅仅传递价值不会再以这种方式工作了
static std::string trim(const std::string& s);
// ^ remove the reference
对于其他类似的功能,我建议您这样做。
或者使用左值调用函数
std::string part = line.substr(colon + 1);
return StringUtils::trim(part);
相关文章:
- 使用共享指针的函数调用,其对象应为 const
- 将参数打包的参数传递到 std::queue 中,以便稍后使用不同的函数调用
- C++调用使用重写函数的父类函数
- 使用动态链接加载程序 <dlfcn.h> 而不是直接函数调用的目的是什么?
- 使用 std::find 时没有匹配的函数调用错误
- 了解在返回值之前和之后使用 EAX 的函数调用
- 从python调用C++函数,使用cython,使用cythonize
- 函数参数的名称与调用函数时使用的变量相同是否有效?
- 使用显式模板参数列表和 [temp.arg.explicit]/3 的函数调用的演绎失败
- 使用成员初始值设定项列表时没有匹配的函数调用错误
- 是否可以使用三元切换/控制/谓词成员函数调用?
- 使用回调函数从构造函数调用虚拟/派生方法的替代方法?
- 使用另一个函数调用一个函数(都在类中)时出现问题.没有错误代码C++
- 如何在使用模板的函数调用的大括号表达式中推导多维数组的大小
- 调用函数并使用文件作为引用
- C++如何调用使用向量的成员函数
- 在 VC++ 中跨函数调用使用双指针进行操作
- 错误:对的调用没有匹配的函数调用-使用VS2013编译
- 通过函数调用使用pyrdown
- 如何检测函数,只有从未使用的函数调用使用cppcheck