C++ compiler short circuit for variables

4 days ago 8
ARTICLE AD BOX

I have the below very trivial code but it explains well the issue. It's clear that y never is used but the C++ compiler complains that y doesn't exist. Is there a way [templates?] which "hides" y for the compiler if the expression is true?

int main() { int x = 1; return true ? x : y; }

It looks here very trivial but imagine this with classes and lot of templates.

Read Entire Article