我在一个类(比方说aaa类)定义了一个变量,如何在另一个类中用啊(比方说bbb)
能不能说的详细一点,我刚学啊。

解决方案 »

  1.   

    class bbb
    {
    public:
       int mem1;
    private:
       int mem2;
    public:
       int GetMem2()
       {
          return mem2;
       }
       void SetMem2(int mem)
       { 
          mem2=   mem;
       }
    }aaa::GetbbbMember()
    {
        bbb    bClass;
        bClass.Mem1=10;
        int aMem2=bClass.GetMem2();
        bClass.SetMem2(aMem2);
    }
      

  2.   

    f你还是找本C++(不是VC)的书吧,打好基础。
      

  3.   

    class bbb
    {
    public:
       int mem1;
    private:
       int mem2;
    public:
       int GetMem2()
       {
          return mem2;
       }
       void SetMem2(int mem)
       { 
          mem2=   mem;
       }
    }aaa::GetbbbMember()
    {
        bbb    bClass;
        bClass.Mem1=10;
        int aMem2=bClass.GetMem2();
        bClass.SetMem2(aMem2);
    }
      

  4.   

    最简单的做法:设为public,不过最好象楼上那为那样做,以免破坏了类的封装性。
      

  5.   

    如 PioneerMan((拓荒者)) 所述,不过别忘了包含相关的头文件
      

  6.   

    class aaa
    {
    public:
       int mem1;
    }
    class bbb:public bb
    {
    public:
       int mem2;
    }
    void main{
    bb test;
    Count<<test.mem1;
    }
      

  7.   

    class aaa
    {
    public:
       int mem1;
    }
    class bbb:public bb
    {
    public:
       int mem2;
    }
    void main{
    bb test;
    Count<<test.mem1;
    }