一、嵌套类
对于Student是不能访问Hand的私有数据成员的,除非将Student定义为Hand的友元类。
如果将嵌套类Hand定义为私有的或受保护的,即使使用Student也是无法访问的。
class Student
{
public:
class Hand
{
public:
int num;
private:
string color;
}
Hand m_hand;
}
int main()
{
Hand hand;//这是非法的,嵌套类对外是不可见的
Student::Hand hand;//合法,但不推荐这么使用,嵌套类通常不允许在外界访问
return 0;
}
二、局部类
void MyClass
{
class Student
{
public:
string name;
static int age;
};
}
局部类在外界是不能够被访问的,因为其作用于就在函数这一个区域。