網路教學(e-Learning)校園社群(e-Community)服務台(e-Service)系所班網(e-Class)登入
位置: 陳安邦 > C++
W15 4
by 陳安邦 2015-12-24 16:48:03, 回應(0), 人氣(306)
#include <cstdlib>
#include <iostream>

using namespace std;

class CWin
{
      private:
              char id;
              int width, height;
              
      public:
             CWin(char i='D',int w=10,int h=10):id(i),width(w),height(h)
             {
                       cout << "CWin()建構元件被呼叫了..." << endl;
             }
             void showmember(void)
             
                  {cout << "window" << id << ":"<< endl;
                  cout << "width=" << width << endl << "height=" << height << endl;}
};
class Ctextwin : public CWin
{
      private:
              char text[20];
              
      public:
             Ctextwin(char *tx)
             {
             cout << "Ctextwin()建構元件被呼叫了..." << endl;
             strcpy(text,tx);
             }
             void showtext()
             {
                  cout << "text=" << text << endl;}
                  
                  };
                  
int main(int argc, char *argv[])
{
    CWin win('A',50,60);
    Ctextwin txt("Hello C++");
    
    win.showmember();
    txt.showmember();
    txt.showtext();
    
    cout << "win物件占了" << sizeof(win) << "bytes" <<endl;
     cout << "txt物件占了" << sizeof(txt) << "bytes" <<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}