What will be printed out as a result of the following code execution?
#include <iostream>
const int SIZE = 5;
struct tester
{
    void foo()
    {
        std::cout << SIZE << std::endl;
    }

    enum 
    {
        SIZE = 3
    };
};

int main(int argc, char** argv)
{
    tester t;
    t.foo();
    return 0;
}
Explanation
Since enum SIZE is defined inside the class, it "covers" the global variable within the class methods. More details: https://en.cppreference.com/w/cpp/language/lookup

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback