草庐IT

function-call-operator

全部标签

c++ - 与 move 构造函数混淆 : unable to call move constructor

我一直难以理解C++中的move构造函数。我用默认构造函数、复制构造函数、move构造函数和析构函数制作了一个简单的类。此外,我定义了一个具有两个重载的函数,一个接受对该类的引用,一个接受对该类的右值引用。我的测试代码如下。#includeclassc{public:c(){std::cout我得到的输出不是我所期望的。以下是我从此代码获得的输出。defaultconstructorcopyconstructorpassedbyreferencedefaultconstructorpassedbyrvaluereferencedestructor除了第3行,我能理解所有行的输出。在第3

c++ - error C2678 : binary '<' : no operator found which takes a left-hand operand. ..(或者没有可接受的转换)

这个问题在这里已经有了答案:HowcanIusestd::mapswithuser-definedtypesaskey?(8个答案)关闭5年前。这是我在map中查找值的代码:boolmyclass::getFreqFromCache(plVariablesConjunction&varABC,vector&freq){std::map>::iteratorfreqItr;freqItr=freqCache.find(varABC);if(freqItr!=freqCache.end()){freq=freqItr->second;returntrue;}}“PlVariablesCon

c++ - "error: no matching function for call to"

我当时在键盘上,我正在尝试使用C++来提高我的技能。我以前从未使用过模板,所以我尝试研究如何使用它们。下面的代码是结果,不幸的是,它不起作用。我确实尝试寻找问题的解决方案,但由于我没有太多使用模板的经验,所以我无法在我的问题和其他问题之间建立任何联系。所以,我决定寻求帮助。templateclassVector2{public:Ax,y;Vector2(Axp,Ayp){this->x=xp;this->y=yp;}};templateclassrayToCast{public:rayToCast(Bangle,Vector2origin,Vector2point1,Vector2po

c++ - C2556 : overloaded function differs only by return type

我正在阅读EffectiveC++,它告诉我“可以重载仅因常量不同而不同的成员函数”。书中的例子是:classTextBlock{public:constchar&operator[](std::size_tposition)const;char&operator[](std::size_tposition);private:std::stringtext;}我下面的示例使用了一个存储指针。classA{public:A(int*val):val_(val){}int*get_message(){returnval_;}constint*get_message(){returnval_

c++ - 如何在 C++ 中重载访问器和增变器 operator[]

我想编写一个String类。并希望使用下标访问我的String中的元素。所以,我写了两个成员函数,一个用来获取String中的元素,另一个用来设置String中的元素。请看下面的代码;#include#includeusingnamespacestd;classString{public:String();String(constchar*s);char&operator[](intindex);charoperator[](intindex)const;private:char*arr;intlen;};String::String(){arr=newchar[1];arr[0]='

c++ - 继续获取 "error: use of undeclared identifier ' cout' 和错误 : reference to overloaded function could not be resolved

我正在编写一个使用许多不同函数的排序程序,你们都可以从我的声明。但是,当我尝试编译和运行我的程序时,我不断遇到这些相同的错误它们如下:error:useofundeclaredidentifier'cout';didyoumean'count'?couterror:referencetooverloadedfunctioncouldnotberesolved;didyoumeantocallit?couterror:useofundeclaredidentifier'endl';didyoumean'end'?cout我不太确定为什么会出现这些错误....我想我已经包含了我需要的一切为

c++ - 在实现 operator[] 时,我应该如何包括边界检查?

首先,我为这么简单的问题提出这么长时间表示歉意。我正在实现一个类,它用作空间填充曲线上的非常长的一维索引或表示该索引对应的笛卡尔坐标的n元组。classcurvePoint{public:friendclasscurveCalculate;//ConstructionandDestructioncurvePoint():point(NULL),dimensions(0){}virtual~curvePoint(){if(point!=NULL)delete[]point;}//MutatorsvoidconvertToIndex(){if(isTuple())calc(this);}v

c++ - 错误 C1090 : PDB API call failed, 错误代码 '0':'

我正在尝试在VisualStudio2013中编译一个C++项目,但出现以下错误errorC1090:PDBAPIcallfailed,errorcode'0':'我需要帮助! 最佳答案 我在MSVC2017中看到了这个错误。我在一个文件中遇到了编译错误(缺少右括号)。此错误发生在以下所有文件上。修复第一个编译错误使它们消失。 关于c++-错误C1090:PDBAPIcallfailed,错误代码'0':',我们在StackOverflow上找到一个类似的问题:

C#/命令行界面 : Destructor not called if Dispose() used in it

我有一个名为“CTransferManaged”的C++/CLI类,其中实现了终结器和析构函数:CTransferManaged::~CTransferManaged(){this->!CTransferManaged();}CTransferManaged::!CTransferManaged(){//Cleanupresources...}此类由名为“CTransfer”的C#类包装,其中包含类型为CTransferManaged的​​对象m_transfer。如果此类的析构函数仅清除对对象m_transfer的引用,我可以看到调用了析构函数(命中断点):~CTransfer(){

c++ - 为什么宏 __STL_FUNCTION_TMPL_PARTIAL_ORDER 应该将模板函数包含在 std_pair.h 中

今天在STL_pair.h中看到如下代码:#ifdef__STL_FUNCTION_TMPL_PARTIAL_ORDERtemplateinlinebooloperator!=(constpair&__x,constpair&__y){return!(__x==__y);}templateinlinebooloperator>(constpair&__x,constpair&__y){return__y我不认为模板函数与偏特化有任何关联的功能模板。我错了吗? 最佳答案 编译器如何处理函数调用在C++中调用函数模板经历了名称查找(标准