main.cpp
来自「C++ Source code from a tutorial」· C++ 代码 · 共 79 行
CPP
79 行
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
class Cat {
public:
string name;
};
class Dog {
public:
string name;
};
class Human {
public:
string name;
};
class Door {
private:
int HowManyInside;
public:
void Start();
void GoThrough(Cat *acat);
void GoThrough(Dog *adog);
void GoThrough(Human *ahuman);
};
void Door::Start() {
HowManyInside = 0;
}
void Door::GoThrough(Cat *somebody) {
cout << "Welcome, " << somebody->name << endl;
cout << "A cat just entered!" << endl;
HowManyInside++;
}
void Door::GoThrough(Dog *somebody) {
cout << "Welcome, " << somebody->name << endl;
cout << "A dog just entered!" << endl;
HowManyInside++;
}
void Door::GoThrough(Human *somebody) {
cout << "Welcome, " << somebody->name << endl;
cout << "A human just entered!" << endl;
HowManyInside++;
}
int main(int argc, char *argv[])
{
Door entrance;
entrance.Start();
Cat *SneekyGirl = new Cat;
SneekyGirl->name = "Sneeky Girl";
Dog *LittleGeorge = new Dog;
LittleGeorge->name = "Little George";
Human *me = new Human;
me->name = "Jeff";
entrance.GoThrough(SneekyGirl);
entrance.GoThrough(LittleGeorge);
entrance.GoThrough(me);
delete SneekyGirl;
delete LittleGeorge;
delete me;
system("PAUSE");
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?