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
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
.
It's the operator for assignment by bitwise OR.
http://en.cppreference.com/w/cpp/language/operator_assignment
int result |= 5;
You cannot initialize an int
and assign something to it at the same time. Initialization and assignment are different things. You'd have to write:
int result = 0;
result |= 5;
If this is what you intend, of course. Since int result |= 5;
is not C++, we can only guess about your intention.