注册 登录
编程论坛 C++教室

请问,类中定义的嵌套类如何调用?

全世界安静 发布于 2012-06-13 13:31, 509 次点击
class  out
{
public:
 int a,b;
 class in
{
 public:
   int a,b;
   in(int x,int y)
    {
      a=x;b=y;
    }
}
 out(int x,int y)
{
  a=x;b=y;
}
in inner;
}
void main()
{
test my_test(1,2);
my_test.inner(3,4);
}
请问错误出在哪里?如何调用嵌套类?
1 回复
#2
lonmaor2012-06-13 18:36
楼主可能还没弄明白为什么要使用嵌套类吧。
class A如果有一个class B的成员,则class B可以在class A内或者class A外定义,这里牵涉到作用域的问题。后果就是你可/不可以在class A的定义之外使用class B类型的对象。
1