草庐IT

overloaded

全部标签

c++ - 为什么 const vector<const pair<...>> 给出 'cannot be overloaded' 错误?

我有这个简单的代码:#include#includevoidfoo(conststd::vector>&networks){for(autop:networks){}}voidbla(conststd::vector>&networks){for(autop:networks){}}这会在bla()中产生一个错误:mrvn@frosties:~%g++-O2-W-Wall-g-std=gnu++17-cbla.ccInfileincludedfrom/usr/include/x86_64-linux-gnu/c++/5/bits/c++allocator.h:33:0,from/usr

c++ - "Overloading"具有不同参数集的纯虚函数

考虑以下代码示例#includeusingnamespacestd;classColor{public:virtualvoidmixColors(Color&anotherColor)=0;};classRGB:publicColor{public:voidmixColors(RGB&anotherColor);};voidRGB::mixColors(RGB&kol){returnRGB(0xABCDEF);}我完全知道为什么这段代码不起作用(RGB中的mixColors()没有实现纯虚函数,因为它有不同的参数集)。但是我想问一下是否有另一种方法可以解决这个问题。假设我想混合颜色,但

c++ - "more than one instance of overloaded function "标准::战俘 "matches the argument list"

使用C++,我尝试#defineTINYstd::pow(10,-10)我为定义了TINY的类(.h)提供了带有#include和命名空间信息的代码#pragmaonce#include"MMath.h"#include#include#includeusingnamespacestd;#defineTINYstd::pow(10,-10)我在.cpp文件中的一些函数实现中使用了TINY,而TINY给出了错误IntelliSense:morethanoneinstanceofoverloadedfunction"std::pow"matchestheargumentlist什么是正确的

C++ 构造函数 : Perfect forwarding and overload

我有两个类,A和B,B派生自A。A有多个构造函数(下例中有2个)。B有一个额外的成员要初始化(它有一个默认的初始化器)。我怎样才能实现B可以使用A的构造函数之一来构造,而不必手动重写B中A的所有构造函数重载?(在下面的示例中,否则我必须为B提供四个构造函数:B():A(){},B(strings):A(s){},B(intb):A(),p(b){},B(strings,intb):A(s),p(b){},而不是只有两个,至少在忽略默认参数的可能性时是这样)。我的方法是完美转发,但是下面的场景会报错:#include#includestructA{A(conststd::string&a

c++ - "invalid comparator": error when overloading the "<" operator

我有一个类需要排序。使用此类的vector,排序时出现“无效比较器”错误。我在我的类中重载了“遵循严格的弱排序。如本post所述.sort需要严格的弱排序。你的comparator不是一个。除其他事项外,对于严格的弱排序,comp(x,x)必须为false。这是我的代码:booloutlierScore::operator这是重载的运算符函数,它所做的本质上是尝试按离群值分数升序排序,核心距离用于打破离群值关系,以及用于打破核心距离关系的ID。StackTrace揭示了这个阶段出现的错误。templateconstexprbool_Debug_lt_pred(_Pr&&_Pred,_T

C++ Armadillo : GCC vs VC++2013: Operator () and overloading

我正在尝试使用ArmadilloC++库开发Linux/Win64应用程序。以下代码在GCC-4.7中编译,但在使用Armadillo提供的VS项目文件的VisualStudio2013中编译失败。#include#include"armadillo"usingnamespacearma;usingnamespacestd;//worksinGCC-4.7//VC++2013:compileerror:C3066voidfoo1(vec::fixed&bar){bar(1)=1.;}//worksvoidfoo2(vec::fixed&bar){bar.at(2)=1.;}//work

c++ - 使用 float 给出 "call to overloaded function is ambiguous"错误

这个问题在这里已经有了答案:Referencetofunctionisambiguous[duplicate](2个答案)关闭6年前。我正在重载函数add(),但是当我使用float数据类型时它显示错误。但是,当我将其更改为double时,它工作正常。为什么float会导致错误?代码是:#includeusingnamespacestd;classstudents{private:inti;floatf;public:voidadd(intb){i=b;cout错误:Infunction'intmain()':[Error]callofoverloaded'add(double)'is

c++ - "Cannot overload functions distinguished by return type alone"是什么意思?

我有这个代码:在标题中:...int32_tround(floatv);...在源代码中...int32_tround(floatv){int32_tt=(int32_t)std::floor(v);if((v-t)>0.5)returnt+1;returnt;}...我在这个网站上四处看了看,但这些例子对我来说似乎有点太复杂了。我正在学习C++,所以如果有人能向我解释错误的含义以及发生错误的原因,我将不胜感激。 最佳答案 Functionoverloading表示有多个方法同名。现在,为了解析正确的重载方法,编译器会查看方法名称和

cv2.error: OpenCV(4.8.1) :-1: error: (-5:Bad argument) in function ‘rectangle‘ > Overload resolution

报错记录cv2.error:OpenCV(4.8.1):-1:error:(-5:Badargument)infunction'rectangle'>Overloadresolutionfailed:> -Argument'thickness'isrequiredtobeaninteger> -Argument'thickness'isrequiredtobeaninteger> -argumentforrectangle()givenbyname('thickness')andposition(4)> -argumentforrectangle()givenbyname('thickness

php - 为什么 PHP 神奇的方法必须公开?

我在我的PHP类中使用了魔法方法,但是当我尝试将它们设为私有(private)时,我收到警告:WARN:Themagicmethod__get()musthavepublicvisibilityandcannotbestaticin...我不想在Eclipse自动完成中使用这些方法。(也许是phpdoc的一种方式?)所以我的问题是,为什么这些方法必须公开? 最佳答案 因为您正在从类之外的范围调用方法。例如://thiscanbeanyclasswith__get()and__setmethods$YourClass=newYourO