草庐IT

has_equal_operator

全部标签

c++ - C++ 中的成员函数模板和重载 operator()

以下代码片段适用于我:classFoo{public:templateT&get(){...}};Foofoo;foo.get()=...;但是,以下代码片段对我不起作用:classFoo{public:templateT&operator()(){...}};Foofoo;foo()=...;错误是:expectedprimary-expressionbefore'>'tokenexpectedprimaryexpressionbefore')'token这两个错误都涉及foo()为什么这不起作用,是否可以解决这个问题? 最佳答案

c++ - std::shared_ptr operator [] 等效访问

在C++17中,std::shared_ptr有一个运算符[]以允许索引基于vector的指针(http://en.cppreference.com/w/cpp/memory/shared_ptr/operator_at)如果这样的运算符不可用,我如何获得类似的访问,我仍然想对元素数组使用智能指针,例如:std::shared_ptrdata;data.reset(newunsignedchar[10]>;//usedata[3]; 最佳答案 像这样:data.get()[3]但是,请记住Nathan在评论中所说的话。std::sh

G++ 4.5 中 std::complex 的 C++11 复制赋值 - 与 'operator+' 不匹配

下面的代码无法使用-std=c++0x开关在g++4.5.0版中编译。我收到以下错误消息:error:nomatchfor'operator+'in'std::pow[with_Tp=float,_Up=int,typename__gnu_cxx::__promote_2::__type=double](((conststd::complex&)((conststd::complex*)(&x))),((constint&)((constint*)(&2))))+y'我相信这与提到的可分配要求有关here.我应该为complex定义自己的复制赋值运算符吗?如果是,怎么办?#includ

c++ - 编译器首先返回 "synthesized method ‘operator=’ 此处需要”

我知道这可能是一个简单的问题,但过去一个半小时我一直在研究它,我真的迷路了。这里是编译错误:synthesizedmethod‘File&File::operator=(constFile&)’firstrequiredhere我有这段代码:voidFileManager::InitManager(){intnumberOfFile=Settings::GetSettings()->NumberOfFile()+1;for(unsignedinti=1;i_files如果在此header中定义:#pragmaonce//C++Header#include//CHeader//local

C# Dll 导入失败 : "The application has failed to start because its side-by-side configuration is incorrect"

我有一个c#.net4应用程序,使用vs2010。我正在尝试导入一个c++dll(基于vs2005)。[DllImport("Card.dll")]我得到了失败:UnabletoloadDLL'Card.dll':Theapplicationhasfailedtostartbecauseitsside-by-sideconfigurationisincorrect.Pleaseseetheapplicationeventlogorusethecommand-linesxstrace.exetoolformoredetail.(ExceptionfromHRESULT:0x800736B

c++ - vector 迭代器 : no match for ‘operator=’

考虑到下面第一个代码片段中的C++代码,我得到了第二个代码片段中指示的编译错误。看起来我在遍历vector实例时做错了。你能告诉我如何克服这些编译问题吗?谢谢。代码中标记了LINE171。片段1(代码)#include#include#includeclassVipAddressSetEntity:BaseEntity{public:VipAddressSetEntity():BaseEntity(){}VipAddressSetEntity(std::string&uuid,std::string&name):BaseEntity(uuid,name){}VipAddressSetE

c++ - 编译错误 : base operand of ‘->’ has non-pointer type ‘Token’

我在尝试编译我的C++代码时遇到标题中提到的错误。我无法理解我在这里做错了什么。编译器在我执行booloperator==(Token)函数时出现问题。我认为这是使运算符(operator)重载的方法。关于为什么编译器不喜欢我提到的任何线索this->terminal还是this->lexeme?classToken{public:tokenTypeterminal;std::stringlexeme;Token*next;Token();booloperator==(Token&t);private:intlexemelength,line,column;};boolToken::o

c++ - 在 C++ 中声明一个 operator+ 函数

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预期结果。另请参阅:StackOverflowquestionchecklist关闭9年前。Improvethisquestion我有一个类(class)Samp。在Samp.cpp中,我可以定义/声明一个像这样的函数Samp&operator+(Samp&other){std::cout这个函数到底是什么?怎么调用它?

c++ - vector < vector > : verify that all have equal sizes

是否有std/boost算法来验证一个vector中的所有vector是否具有相同的大小?推而广之,所有元素的属性都相同吗?在下面的示例中,我使用了我正在寻找的假设的std::all_equal:typedefstd::vectorLine;std::vectorlines;lines.push(Line(10));lines.push(Line(11));autoequalLengths=std::all_equal(lines.begin(),lines.end(),[](constLine&x){returnx.size();});(并且通过扩展:std::vectorvec;a

c++ - gcc编译C++代码: undefined reference to `operator new[](unsigned long long)'

有一段C++代码:#includeintmain(){intb=sizeof('a');if(b==4)printf("I'maCprogram!\n");elseprintf("I'maC++program!\n");}像这样编译:gccmain.cpp-omain它成功并给出:I'maC++program!然后在函数main的某处添加一行int*p1=newint[1000];它失败了:C:\Users\...\AppData\Local\Temp\cccJZ8kN.o:main1.cpp:(.text+0x1f):undefinedreferencetooperatornew[]