+ 3
why the output here equals 11 not 10 ?
#include<iostream> int foo() { return 10; } struct foobar { static int x; static int foo() { return 11; }}; int foobar::x = foo(); int main() { std::cout << foobar::x ; }
4 Answers
+ 3
static int foo() forbids int foo() there, when it is there... You can call only static member directly or through reference of class name.
So there foo() refers to static int foo() of struct foobar first..
+ 3
Don't no but when we comment out the struct foo().. Then output is 10..
https://stackoverflow.com/questions/23329382/function-and-struct-having-the-same-name-in-c
+ 3
Mihir Lalwani
when i use
std::cout <<foo(); // output 10
std::cout <<foobar::foo(); //output 11
I'm fine with these two statments
but i can't understand this
std::cout << foobar::x ; // ??
why it outputs 11 ?
+ 1
Aly Alsayed check above link...