草庐IT

Bitwise_operation

全部标签

c++ - 类没有成员 "operator<<"

我已通读Shouldoperator和OverloadingInsertionOperatorinC++,看起来像类似的问题,但没有解决我自己的问题。我的头文件:usingnamespacestd;classAnimal{private:friendostream&operator我的客户:usingnamespacestd;intAnimal::getnumber(){returnnumber;}ostream&Animal::operator实现很简单,但我收到错误:在cpp中-错误:类“Animal”类没有成员“operator我真的不明白,因为我已经将插入运算符声明为Anima

c++ - "no ' operator++(int) ' declared for postfix '++ ' [-fpermissive]"枚举

这个问题在这里已经有了答案:HowcanIiterateoveranenum?(28个答案)Whycan'tIincrementavariableofanenumeratedtype?(10个答案)关闭9年前。我有枚举enumProgramID{A=0,B=1,C=2,MIN_PROGRAM_ID=A,MAX_PROGRAM_ID=C,}CurrentProgram;现在,我正尝试像这样递增CurrentProgram:CurrentProgram++,但编译器提示:没有为后缀'+声明'operator++(int)'+'[-fpermissive]。我认为有这样一个运算符可以增加“枚

c++ - 如何在 operator += 中调用 operator +

operator+=这样定义对吗?!voidoperator+=(constBigNumber&other){*this=(*this)+other;}在这样的类中:classBigNumber{public://....BigNumberoperator+(constBigNumber&other){returnsum(other);}//....} 最佳答案 是的。但正确的方法是根据operator+=来实现operator+:structfoo{intvalue;foo&operator+=(constfoo&other){v

c++ - ‘operator ==’ 中的 ‘a == b’ 不匹配

#includeusingnamespacestd;classfamily{private:doubleweight;doubleheight;public:family(doublex,doubley);~family();doublegetWeight();doublegetHeight();doublesetWeight();doublesetHeight();booloperator==(constfamily&,constfamily&);};boolfamily::operator==(constfamily&a,constfamily&b){return(a.getWei

c++ - SSE 内在函数 : masking a float and using bitwise and?

基本上这个问题与x86汇编器有关,您有一个数字,您希望使用and将其设置为零或数字本身。.如果你andnumber为负数你会得到number本身,但如果你and它与零你得到零。现在我在使用SSEinstrinsics时遇到的问题是float在二进制中与double不同(或者我弄错了)。无论如何,这是代码,我尝试使用各种float来掩盖第二个和第三个数字(分别为127.0f和99.0f),但没有成功。#include#includevoidprint_4_bit_num(constchar*label,__m128var){float*val=(float*)&var;printf("%

c++ - 避免使用 "child"延迟 `operator<<` 对象构造

假设我有一个存储std::vector的容器对象多态child。structChild{Child(Parent&mParent){/*...*/}virtual~Child(){}};classParent{private:std::vector>children;templateauto&mkChild(TArgs&&...mArgs){//`static_assert`that`T`isderivedfrom`Child`...children.emplace_back(std::make_unique(std::forward(mArgs)...));return*childr

c++ - operator-> 重复直到它返回一个非类类型的值

根据13.3.1.2/8,或更好footnote-129(强调我的):[...]Theprocessrepeatsuntilanoperator->functionreturnsavalueofnon-classtype.我以为我知道operator->是如何工作的(让我说,它是基于返回类型的递归方式),但我发现我完全不知道关于它实际上是如何工作的(我的意思是,它的返回类型)。当我找到它时,我想知道是否真的可以为通用结构S定义和使用类似doubleoperator->()的东西,因为我已经从来没有这样使用过这样的运算符。例如,请考虑以下代码:structS{constexprdoubl

c++ - 类型没有可行的重载 operator[]

我定义了一个类型:typedefunordered_map>Graph;我有一把key:stringv="A12";当我尝试使用key访问列表时:for(autow=g[v].begin();w!=g[v].end();w++){...}g是Graph类型,我得到错误:Noviableoverloadedoperator[]fortype'constGraph'我该如何解决这个问题? 最佳答案 问题是g是一个constgraph&。索引运算符[]可能需要为map创建一个新元素,从而改变它。这就是为什么你不能在constgraph&上

c++ - operator<< 无法输出 std::endl -- 修复?

下面的代码在应该只输出std::endl时出错了:#include#includestructMyStream{std::ostream*out_;MyStream(std::ostream*out):out_(out){}std::ostream&operatorstructFoo{OutputStream*out_;Foo(OutputStream*out):out_(out){}voidtest(){(*out_)foo(&out);foo.test();returnEXIT_SUCCESS;}错误是:stream1.cpp:19:error:nomatchfor'operato

c++ - STL operator= Visual Studio 2010 的行为发生变化?

我正在尝试使用VisualStudio2010(C++)编译QtScriptGenerator(gitorious),但遇到了编译错误。在寻找解决方案的过程中,我偶尔会看到自VS2008以来由于VS2010的STL实现的变化和/或c++0x一致性变化而引入的编译破损。知道下面发生了什么,或者我该如何解决它?如果有问题的代码似乎是QtScriptGenerator的,我想我会更容易修复它。但在我看来,有问题的代码可能在VS2010的STL实现中,我可能需要创建一个解决方法?附言。我对模板和STL很陌生。我有嵌入式和控制台项目的背景,这些项目直到最近才经常被避免以减少内存消耗和交叉编译器风