3

Recently, I found that below code is working, but I don't understand why. Why can the compiler use classNameA::classNameA::variable to find the variable, but why not namespaceB::namespaceB::variable?

namespace Cool  
{  
    int a = 5;  
}

class Good    
{  
public:  
    const static int b = 10;  
};

int main()  
{  
    //std::cout << Cool::Cool::a <<std::endl; //why this line not working?  
    std::cout << Good::Good::Good::b << std::endl; // why can the compiler find the variable b?  
    return 0;   
}
codeling
  • 11,056
  • 4
  • 42
  • 71

0 Answers0