jjzjj

operands

全部标签

c++ - 后缀(前缀)增量、左值和右值(在 C 和 C++ 中)

我刚刚了解到以下事实:Theresultofaprefixincrement(++var_name)isanR-valueinC(atleast,IamsurethatitisnotaL-valueinC),butitisanL-valueinC++.Theresultofapostfixincrement(var_name++)isanR-valueinC(atleast,IamsurethatitisnotaL-valueinC).ThisisalsotrueinC++(Itsaystheresultisaprvalue).我在VS2010(.cpp和.c)和Ubuntu(gcc和

c++ - 错误 : invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'

我想获取z_Data的第48个字符的第6位{charc=pPkt->z_Data[47];//thisz_Dataisacharbufferstd::cout>3)&1>4)&1>5)&1 最佳答案 优先级高于&,所以你需要:std::cout>3)&1)>4)&1)>5)&1) 关于c++-错误:invalidoperandsoftypes'int'and''tobinary'operator https://stackoverflow.com/questions/246

c++ - 编译为 C++ 但不是 C(错误 : lvalue required as unary '&' operand)

当我使用C++而不是C时,这一行编译:gmtime(&(*(time_t*)alloca(sizeof(time_t))=time(NULL)));//用alloca创建一个左值我对这种差异感到惊讶。甚至没有针对C++的警告。当我指定gcc-xc时,消息是:playground.cpp:25:8:error:lvaluerequiredasunary'&'operandgmtime(&(*(time_t*)alloca(sizeof(time_t))=time(NULL)));^这里的&不就是一个address-of操作符吗?为什么在C和C++中不同?虽然我可以在C中使用复合字面量,但

c++ - 错误 C2106 : '=' : left operand must be l-value

查看有关错误C2106的其他问题,我仍然不知道我的代码有什么问题。编译时出现以下错误:c:\driver.cpp(99):errorC2106:'=':leftoperandmustbel-valuec:\driver.cpp(169):errorC2106:'=':leftoperandmustbel-value代码行如下:payroll.at(i)=NULL;//Line99payroll.at(count++)=ePtr;//Line169我不明白为什么会抛出这个错误。在这个项目中,我将我的driver.cpp从员工对象指针数组更改为我制作的自定义Vector模板。我声明Vect

c++ - 错误 : operand out of range (64 is not between 0 and 31)

我在PowerPC上遇到GCC内联汇编。该程序使用-g2-O3编译良好,但使用-g3-O0编译失败。问题是,我需要在调试器下观察它,所以我需要没有优化的符号。程序如下:$cattest.cxx#include#undefvectortypedef__vectorunsignedcharuint8x16_p;uint8x16_pVectorFastLoad8(constvoid*p){longoffset=0;uint8x16_pres;__asm("lxvd2x%x0,%1,%2\n\t":"=wa"(res):"g"(p),"g"(offset/4),"Z"(*(constchar(

c++ - 错误 C2678 : binary '=' : no operator found which takes a left-hand operand of type 'const Recipe' (or there is no acceptable conversion)

我正在尝试对每个元素中包含一个int和一个字符串的vector进行排序。它是一个称为vector食谱的类类型的vector。出现上述错误,这是我的代码:在我的Recipe.h文件中structRecipe{public:stringget_cname()const{returnchef_name;}private:intrecipe_id;stringchef_name;在我的Menu.cpp文件中voidMenu::show()const{sort(recipes.begin(),recipes.end(),Sort_by_cname());}在我的Menu.h文件中#include

c++ - 如何修复 "invalid operands to binary expression"错误?

我没有使用C++的经验,一直卡在编译器生成二进制表达式的无效操作数classAnimal{public:intweight;};intmain(){Animalx,y;x.weight=33;y.weight=3;if(x!=y){//dosomething}}我想使用x并与y进行比较,而不修改主代码中的代码,即(x.weight!=y.weight)。我应该如何从外部类或定义中解决这个问题? 最佳答案 或者,您可以将运算符重载添加为非成员:#includeusingnamespacestd;classAnimal{public:i

c++ - 迭代器模式 - 错误 C2679 : binary '<<' : no operator found which takes a right-hand operand of type 'std::string'

这个问题在这里已经有了答案:errorC2679:binary'(1个回答)关闭5年前。我正在尝试使用迭代器模式进行迭代和打印,但出现错误这里是错误:errorC2679:binary'couldbe'std::basic_ostream&std::operator>(std::basic_ostream&,constchar*)'这是错误的来源std::coutgetName();#ifndef_ROBOT1_#define_ROBOT1_namespaceguitars{namespaceComposite{namespaceInventoryParts{usingnamespac

C++ 连接字符串导致 "invalid operands of types ‘const char*’ 和 ‘const char"

我想连接两个字符串,但出现错误,我不知道如何克服这个错误。有什么方法可以将这个constchar*转换为char吗?我应该使用一些取消引用吗?../src/main.cpp:38:error:invalidoperandsoftypes‘constchar*’and‘constchar[2]’tobinary‘operator+’make:***[src/main.o]Error1但是,如果我尝试以这种方式组成“bottom”字符串,它会起作用:bottom+="|";bottom+=tmp[j];bottom+="";这是代码。#include#include#include#inc

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