本文介绍了| =在C ++中是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码行

  int i = 0; 
结果| = EXPECT_EQUAL(list.size(),3);

| = 的男人是什么?

我正在尝试编译以下内容:

  int结果| = 5 ; 

但出现错误:

  aaa.cpp:26:16:错误:'| ='令牌


解决方案

a | = b; 只是 a = a |的语法糖。 b; 。相同的语法对C ++中的几乎所有运算符均有效。



但是 int i | = 5; 是错误的,因为在定义行中必须进行初始化,

  int i = 3;  

  int i = 3; 
i | = 5;

有效,并且会将值7(3 | 5)赋予 i


I have code line

int i =0;
result |= EXPECT_EQUAL(list.size(),     3);

What does |= mens?

I was trying to compile something like:

int result |= 5;

but got error:

aaa.cpp:26:16: error: expected initializer before ‘|=’ token
解决方案

a |= b; is just syntactic sugar for a = a | b;. Same syntax is valid for almost every operator in C++.

But int i |= 5; is an error, because in the definition line you must have an initialisation, that is an expression that does not use the variable being declared.

int i=3;
i |= 5;

is valid and will give value 7 (3 | 5) to i.

这篇关于| =在C ++中是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:59