#include<iostream>
using namespace std;
class Shengxb{
public:
    Shengxb(int size=0);
    ~Shengxb();
    int &operator[](int i);
    void pull();
    void connect(Shengxb &BB);
private:
    int size;
    int *shengxb;
};

Shengxb::Shengxb(int sz){
    if(sz<=0)
        cout<<"请重输:"<<endl;
    else
    {
        size = sz;
        shengxb = new int[size];
    }
}

Shengxb::~Shengxb(){
    delete [] shengxb;
}

void Shengxb::pull(){
    cout<<"输入数据:"<<endl;
    for(int i=0;i<size;i++)
        cin>>shengxb[i];
}

int &Shengxb::operator [](int i){
    if(i<0||i>=size)
        cout<<"out"<<endl;
    return shengxb[i];
}

void Shengxb::connect(Shengxb &BB){
    Shengxb DD = *this;
    shengxb = new int[DD.size+BB.size];

    size = DD.size+BB.size;
    int i,j,k=0;
    for(i=0,j=0;k<size;k++)
        if(DD[i]>=BB[j])
        {
            shengxb[k]=BB[j];
            j++;
            if(j>BB.size)break;
        }
        else
        {
            shengxb[k]=DD[i];
            i++;
            if(i>DD.size)break;
        }
    if(j>=BB.size)
        for(k=k;k<size;k++,i++)
            shengxb[k]=DD[i];
    if(i>=DD.size)
        for(k=k;k<size;k++,j++)
            shengxb[k]=BB[j];
    cout<<"升序表为:"<<endl;
    for(k=0;k<size;k++)
        cout<<shengxb[k]<<"  ";
    cout<<endl;
} 
void main(){
    Shengxb AA(3),BB(2);
    AA.pull();
    BB.pull();
    AA.connect(BB);
}




输入数据:
1 2 3
输入数据:
1 2
out
out
升序表为:
1 1 2 2 3


为什么有两个out表示溢出了呢??