W17 實作1
#include <cstdlib>
#include <iostream>
using namespace std;
class father
{
public:
char id;
int width,height;
father(char i='D',int w=10,int h=10):id(i),width(w),height(h)
{
cout << "father()建構元件被呼叫了..." << endl;
}
void showmember(void)
{
cout << "window" << id << ":";
cout << "width" << width << ",height" << height << endl;
}
};
class son : public father
{
private:
char text[20];
public:
son(char *tx)
{
cout << "son()建構元件被呼叫了..." << endl;
strcpy(text,tx);
}
void showtext()
{
cout << "text = " << text << endl;
}
};
int main(int argc, char *argv[])
{
father f('A',50,60);
son txt("HALLO C++");
f.showmember();
txt.showmember();
txt.showtext();
system("PAUSE");
return EXIT_SUCCESS;
}