11.8c++

#include

using namespace std;

class Array
{
public:
Array(int x)
{
Count = x;
p= new int[Count];
for(int j=0;j<Count;j++)
p[j]=j;

    }
    Array(const Array& a)
    {
        int z;
        Count = a.Count;
        p=new int[Count];//±ðÍü¼Ç
        for(z=0;z<a.Count;z++)
            p[z]=a.p[z];

    }
    int & operator[](int x)
    {
        return *(p+x);
    }
    ~Array()
    {
        delete []p;
    }
    void show()
    {
        int i;
        for(i=0;i<Count;i++)
        {
            cout<<p[i];

        }
    }

protected:
    int Count;
    int *p;

};

int main()
{
Array a(10);
a.show();
Array b(a);
b.show();
return 0;
}

猜你喜欢

转载自blog.csdn.net/cruel2436/article/details/83855742