What will be the program exit code?
struct S {
    static int i;
    S()         { ++i; }
    S(const S&) { ++i; }
};

int S::i = 0;

int main() {
    S v(S());
    return S::i;
}
Explanation
The S() construct in this context denotes the type of a pointer to a function that takes no parameters and returns an object of type S.
Thus, S v(S()); is a forward declaration in the local scope of the function with the name v, the type of the return value S and the type of the argument - a pointer to a function without parameters with the type of the return value of S.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes