草庐IT

has_equal_operator

全部标签

c++ - 重载 'operator++' 必须是一元或二元运算符(有 3 个参数)

我有一个头文件和一个.cpp文件。我正在尝试实现前缀和后缀运算符重载,但在设置重载时我一直收到此错误。分数.h#ifndefFRACTION_H#defineFRACTION_H#includeusingnamespacestd;classFraction{public:Fraction();Fraction(int,int);intgetTop(){returnm_top;}intgetBottom(){returnm_bottom;}voidset(intt,intb){m_top=t;m_bottom=b;reduce();}protected:private:voidreduc

C++ fatal error C1001 : An internal error has occurred in the compiler

在Release模式下编译时出现以下错误。1>d:\users\eyal\projects\code\yalla\core\src\runbox\win32\window.cpp:fatalerrorC1001:Aninternalerrorhasoccurredinthecompiler.1>(compilerfile'f:\dd\vctools\compiler\utc\src\p2\main.c',line249)1>Toworkaroundthisproblem,trysimplifyingorchangingtheprogramnearthelocationslistedab

c++ - 在什么情况下 std::unique_ptr::operator[] 可能抛出?

我的类有一个operator[],它所做的就是在unique_ptr上调用std::unique_ptr::operator[]>成员(member)。相关部分就是这样:templatestructFoo{T&operator[](constsize_tpos)constnoexcept{returndata_[pos];}std::unique_ptrdata_;};我已将运算符标记为noexcept。但是,unique_ptr::operator[]不是noexcept。我无法找出原因,也不知道我是否可以假设它永远不会抛出。unique_ptr::operator[]本身没有在文档

c++ - 如何在 C++ 中为多态类实现 operator==

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:What’stherightwaytooverloadoperator==foraclasshierarchy?我有一个基类和几个派生类,如下面的代码所示:classBase{public:friendbooloperator==(constBase&,constBase&);virtual~Base(){}private:virtualboolequals(constBase&other)const=0;};booloperator==(constBase&lhs,constBase&rhs){return

c++ - std::set<K, C>::operator<(const std::set<K, C>&) 不使用 C() 但 std::less()

无法删除我自己的问题,所以改写它... 最佳答案 这实际上不是实现中的错误,尽管它可以说是标准中的错误:23.2.1Generalcontainerrequirements[container.requirements.general]13Table98listsoperationsthatareprovidedforsometypesofcontainersbutnotothers.Thosecontainersforwhichthelistedoperationsareprovidedshallimplementtheseman

c++ - std::map operator [] - 未定义的行为?

我一直在思考以下问题:这是否会导致未定义的行为,为什么?std::mapm;m[10]+=1;它可以完美地编译和运行,但不能证明任何事情。它类似于一个常见的UB示例i=++i+i++;因为operator[]确实有副作用,但另一方面假设任何评估顺序(从左到右从右到左)将我带到map的相同最终状态附言可能相关:http://en.cppreference.com/w/cpp/language/eval_order编辑抱歉,我应该写的m[10]=m[10]+1; 最佳答案 没有什么是未定义的。operator[]返回映射条目的左值引用(

c++ - 初始化列表作为 operator[] 的参数

这个问题与讨论的问题有关here.我尝试使用初始化列表来创建要传递给operator[]的参数。#include#includestructA{std::string&operator[](std::vectorvec){returnvec.front();}};intmain(){//okstd::vectorvec{"hello","world","test"};Aa;//error:couldnotconvert'{"hello","world","test"}'to'std::vector...'a[{"hello","world","test"}];}我的编译器(GCC4.6

c++ - std::vector::assign/std::vector::operator=(const&) 是否保证重用 `this` 中的缓冲区?

如果我将一个vector分配或复制到另一个vector(其容量与前者的大小相同或更大),我可以假设后者的缓冲区将被重用吗?下面的例子证明我可以,但是,标准保证吗?std::vector::assign和std::vector::operator=在这方面的行为有什么不同吗?#include#include#includeintmain(){std::vectora{1,2,3,4,5};std::vectorb{1,2,3,4};std::vectorc{1,2,3,4,5,6,7,8,9,10};std::coutLiveexample.更新:Thisanswer提到voidassi

c++ - C1001 : An internal error has occurred in the compiler

这应该是不言自明的。我正在尝试实现分布排序,但MSVC编译器崩溃了。这似乎是用我的SFINAE检测成员函数的特定情况,如果我不将indexert传递给函数,或者替换has_get_index,这似乎不会发生。如果我删除剩余的索引器重载中的任何一个,它也不会发生。如果sortable有一个getIndex()const成员,问题仍然存在。1>test.cpp(34):fatalerrorC1001:Aninternalerrorhasoccurredinthecompiler.1>(compilerfile'msc1.cpp',line1420)1>Toworkaroundthispro

c++ - QMap/QHash operator[] 返回引用有效性

我想知道对Qt容器内的值的引用,尤其是QHash或QMap的有效期有多长。我所说的有效是指在插入或删除其他元素后是否保证仍指向映射/哈希内的正确位置。让我们看下面的代码:QHashdict;//orQMapdict;dict.insert('a',1);int&val(dict['a']);dict.insert('b',2);val=3;//在最后一行设置值是否会正确地将与a关联的值更新为3或者它会导致段错误还是未定义(所以有时工作,其他时候出现段错误,这取决于是否必须在内部重组数据结构,例如调整哈希表数组的大小)。QMap和QHash的行为是否相同,或者一个有效而另一个无效?