enter 發表於 2015-11-10 14:39:43

有建構子者都要有初始值

class sample{
        int j;
public:
        sample(int x){j=x;}
        void get(int y){j=y;}
        void show(){cout<<j<<endl;}
};

int main(){

        sample ob(123); //因為有建構子所以要給予初值
       
        ob.get(999);//再改值也可以,但不能沒給初值

        bo.show();

        return 0;
}
頁: [1]
查看完整版本: 有建構子者都要有初始值