Is there a way to declare, assign and compare a variable to an expression in an if construction in such a way that it is only defined in the scope of the if construction?
You can only do a declaration OR boolean logic in an if statement. The C++ spec says so somewhere, forgot where exactly. Therefore a code like:
if (int x = 3 && x == 3) {} will never compile because it will also throw the error that x is used uninitialized