C++编译错误只有一个候选函数
C++ Compilation Error With only one candidate function
编译代码时,出现以下错误。如果只有一个候选人,为什么要抛出错误?。为什么它不能使用它?
错误:调用没有匹配函数
TemplateParameters::reset_template_params( const char [8], const char [11], std::vector<const Channel*>, bool, std::map<int, String, std::less<int>, std::allocator<std::pair<const int, String> > >& )
'
注:候选人为:
void TemplateParameters::reset_template_params( String, String, std::vector<const Channel*>&, bool, std::map<int, String, std::less<int>, std::allocator<std::pair<const int, String> > >& )
调用和候选之间有两个区别:
-
前两个
String
参数。如果不存在从C字符串文字到此类的隐式转换,则该调用是不可能的。 -
vector
与vector&
参数。我假设你正在将一个临时向量传递给一个新创建的向量。编译器不允许这样做,因为您无法将临时引用绑定到非常量引用。使用const引用将在这里起作用。但这当然意味着不能在方法内部修改参数。既然你没有展示你是如何调用代码的,这当然是无聊的猜测。
您正在传递字符串文字,而您的函数需要String
s。您的String
类是否有一个(非explicit
)构造函数,可以用char const*
调用?如果没有,那就是你的问题。
检查你的参数,Can,你给出的每一件事,都可以直接转化为参数,例如:字符串不能同时为const char[8]或const char[11],除非指定并显式转换
您的函数调用:
TemplateParameters::reset_template_params()
传递了5个参数,编译器找不到具有相同参数的函数。因此出现了错误。
编译器可以找到函数TemplateParameters::reset_template_params()
,但您传递的参数与编译器为函数TemplateParameters::reset_template_params()看到的函数声明不匹配。
您需要有一个TemplateParameters::reset_template_params()
的重载版本,该版本的参数与您调用函数时使用的参数完全相同。
- 有一个构造函数,但有两个析构函数
- c++ 在类中声明私有的向量,但有一个 get 函数
- 是否可以有一个模板函数,可以将向量和非向量类型都作为参数
- 是否有一个标准函数可以打印/监视stdin文件的内容,同时将数据留在stdin中
- 错误:在“(”标记之前进行预期的构造函数、析构函数或类型转换.即使我有一个构造函数
- Caffe 中是否有一个训练函数来训练来自 c++ 代码的网络
- 我可以有一个模板函数指针的 std::vector 吗?
- 有可能在同一个字符序列上有一个类似函数的宏和一个类似对象的宏吗
- 为什么有一个构造函数同时接受initializer_list和一个参数包
- 我有一个构造函数,但我需要将输出返回到 main.cpp.我无法使用获取字符串功能!!任何想法如何实现这一目标?
- 有一个构造函数块是可以接受的样式吗
- 是否有一个随机函数可以生成 0 到 1 之间的数字
- win32(windows.h)中是否有一个方便函数可以将lParam转换为POINT
- C++是否有一个自由函数“size(object)”
- 是否有可能在__stdcall中有一个导出函数并且其名称未被修改?
- 我如何在c#上为一个包装的c++方法写一个签名,该方法的参数中有一个指向函数的指针
- 为什么抽象类有一个虚函数表?
- 是否有一个GetModuleThreadId函数
- C++编译错误只有一个候选函数
- C++中是否有一个标准函数,它接受一个参数并返回相同的参数