C++编译错误只有一个候选函数

发布于 2024-11-15 04:54:27 字数 694 浏览 5 评论 0 原文

编译我的代码时出现以下错误。如果只有一个候选者,为什么会抛出错误?为什么不能用呢?

错误:没有匹配的函数来调用 '

TemplateParameters::reset_template_params(
  常量字符 [8],
  常量字符[11],
  std::vector,
  布尔,
  std::map,
    std::allocator > >&
)

'

注意:候选人是:

void TemplateParameters::reset_template_params(
  细绳,
  细绳,
  std::vector&,
  布尔,
  std::map,
    std::allocator > >&
)

While compiling my code I am getting the following error. Why is throwing an error if there is only one candidate?. Why can't it can use it?

error: no matching function for call to '

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> > >&
)

'

note: candidates are:

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> > >&
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

勿挽旧人 2024-11-22 04:54:27

调用和候选之间有两个区别:

  • 前两个 String 参数。如果不存在从 C 字符串文字到此类的隐式转换,则无法进行调用。

  • 向量向量&参数。我冒险假设您将临时值传递给函数的新创建的向量。编译器不允许这样做,因为您无法将临时引用绑定到非常量引用。在这里使用常量引用是可行的。但这当然意味着不能在方法内部修改参数。

    由于您没有显示如何调用代码,这当然是无意义的猜测。

There are two differences between the call and the candidate:

  • The first two String arguments. If no implicit conversion from a C-string literal to this class exists, the call isn’t possible.

  • The vector vs. vector& parameter. I’m going out on a limb and assume that you are passing a temporary to a newly created vector to the function. The compiler doesn’t allow this since you cannot bind a temporary to a non-const reference. Using a const-reference instead would work here. But that of course means that the parameter cannot be modified inside the method.

    Since you didn’t show how you called the code this is of course idle speculation.

夜还是长夜 2024-11-22 04:54:27

您正在传递字符串文字,并且您的函数需要 String。您的 String 类是否有一个可以使用 char const* 调用的(非显式)构造函数?如果没有,那就是你的问题了。

You are passing in string literals, and your function expects Strings. Does your String class have a (non-explicit) constructor that can be called with a char const*? If not, there's your problem.

一杆小烟枪 2024-11-22 04:54:27

检查你的参数,可以,你给的每一个东西,直接翻译成参数,例如:
除非显式指定和转换,否则字符串不能同时为 const char[8] 或 const char[11]

Check up your parameters, Can, every thing you have given, directly translate into the parameters, e.g:
String cannot be both const char[8] or const char [11] unless specified and converted explicitly

香草可樂 2024-11-22 04:54:27

您的函数调用:

TemplateParameters::reset_template_params() 传递了 5 个参数,编译器找不到具有相同参数的函数。因此出现了错误。

编译器可以找到函数 TemplateParameters::reset_template_params(),但您传递的参数与编译器看到的函数 TemplateParameters::reset_template_params() 的函数声明不匹配。

您需要有一个 TemplateParameters::reset_template_params() 的重载版本,其参数与您调用函数时使用的参数完全相同。

Your function call:

TemplateParameters::reset_template_params() passes 5 parameters and compiler cannot find a function which has the same parameters. Hence the error.

The compiler can find a function TemplateParameters::reset_template_params() but the parameters you are passing do not match to the function declaration which compiler sees for function TemplateParameters::reset_template_params().

You need to have a overloaded version of TemplateParameters::reset_template_params() with exactly the same parameters you are calling your function with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文