Greetings, everyone!
Examining my own code, I came up to this interesting line:
const CString &refStr = ( CheckCondition() ) ? _T(\"foo\") : _T(\"bar
Simpler example: const int x = foo();
This constant too has to be initialized, and for that foo()
needs to be called. That happens in the order necessary: x comes into existance only when foo returns.
To answer your additional questions: If foo()
would throw
, the exception will be caught by a catch()
somewhere. The try{}
block for that catch()
surrounded const int x = foo();
obviously. Hence const int x
is out of scope already, and it is irrelevant that it never got a value. And if there's no catch
for the exception, your program (including const int x
) is gone.
C++ doesn't have random goto
's. They can jump within foo()
but that doesn't matter; foo()
still has to return.