Hacker News new | ask | show | jobs
by quietbritishjim 652 days ago
> The result of the expression is the condition. Thus, in your example, the bool check would apply to "s", after the expression is evaluated.

This is a contradiction. There is no expression in my code that evaluates to s. foo() is an expression, and then std::string s = ... is assignment initialisation, which is not an expression.

Edit: I suppose that if I used another form of initialisation, the answer becomes a bit more obvious:

   if (std::string s('x', 3))
(Not that this makes sense but just the point is to use a constructor with more than one argument.) In this case it's clear the test has to be the just-initialised variable. In fact there could be no arguments at all!
1 comments

You are using definitions that I am not familiar with. Maybe it's because we speak different programming languages :-)

x = y is an expression statement in C++, which can be evaluated in an "if" for its side-effects.

https://en.wikipedia.org/wiki/Expression_(computer_science)

But Type x = y isn’t.