Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access an object in C++ other than using an expression?

According to C++03 3.10/1 every expression is either an lvalue or an rvalue. When I use = to assign a new value to a variable the variable name on the left of the assignment is an lvalue expression. And it looks like whatever I try to do with a variable it'll still use some expression.

Is there any way to manipulate a variable in C++ other than by using an expression?

like image 752
sharptooth Avatar asked Dec 10 '12 11:12

sharptooth


1 Answers

The only way would be through a statement, yet not via an expression which is part of such a statement. An example would be a definition, std::string x;. This calls the default ctor on x. But does this count as a manipulation to you?

There aren't that many other statements, actually. Loop control statements cannot change objects themselves other than via side effects of the loop control expressions. goto, break and continue can't do it at all. throw is an expression and catch() can't change anything, so that pair is also irrelevant. I don't think there's any other non-expression-statement.

like image 134
MSalters Avatar answered Sep 21 '22 06:09

MSalters