the following code will help me illustate my question to you directly:
#include<iostream>
class foo {
public:
class bar {
public:
bar(int a) : m_a(a) {}
void say() { std::cout << m_a << std::endl;}
private:
int m_a;
};
};
int main()
{
foo::bar b(3);
b.say();
}
as you see, to declare a object of class bar, we use the quite namespace like syntax “foo::bar”, although actually bar is just an embebed class type in class foo. my question
is does the scope of a class itself is a namespace in c++?
The class is not a namespace, it is a scope. You already used this term yourself. Namespace is a scope. Class is a scope as well. The
::operator is a scope resolution operator. Scope, not namespace, is the fundamental term that can act as a “common denominator” in this case. Scope is the reason why you can use the::operator with both classes and namespaces on the left-hand side.