W15 4
#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;
}