What happens if we use the enum name as a function in c++? To elaborate, let me put the following code snippet
enum check{
HELLO,
HI,
HOWDY,
SALAM,
SALOM,
STOP
};
void main() {
int p = check();
cout<<p;
}
I could assume it may be invoking the default constructor in case of a class or structure, but what happens with an enum?
And if it is some sort of a construtor-like method, does it return 0 ? because ‘p’ was set to 0.
It uses a value-initialized (just like a
classor astruct)checkto copy-initialize theint, and it returns0.And to be clear, you’re not using it as a function, that’s the syntax for value-initialization.
Just like
isn’t using the type
intas a function.