The following code compiles in C++
struct foo
{
int a, b;
};
struct foo foo()
{
struct foo a;
return a;
}
int main(void) {
foo();
return 0;
}
- Is it supposed to be allowed to have a struct and a function with the same name ?
Since it compiles I then go on and try to declare an object of type
foo. Is there a way? It seems impossible to do :foo a; // error: expected ‘;’ before ‘a’ foo a{}; // error: expected ‘;’ before ‘a’ foo a(); // most vexing parse would kick in any way
struct foo f; std::cout<<f.a<<"\n";_stathere: learn.microsoft.com/en-us/cpp/c-runtime-library/reference/…