code.club

標題: 有建構子者都要有初始值 [打印本頁]

作者: enter    時間: 2015-11-10 14:39
標題: 有建構子者都要有初始值
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;
}




歡迎光臨 code.club (http://code.club/) Powered by Discuz! X3.2