Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- class human{
- private:
- char *h;
- public:
- human(char *s){
- h = s;
- }
- virtual void eat(){
- printf("Поел %s\n", h);
- }
- virtual ~human();
- };
- class Maxim : public human{
- public:
- Maxim(char *s) : human(s){}
- };
- class Sanya : public human{
- private:
- int years;
- public:
- Sanya(char *n, int y) : human(n){
- years = y;
- }
- int get_years();
- };
- int Sanya::get_years(){
- return years;
- }
- int main() {
- human *as = new Maxim((char*)"Maxim");
- as->eat();
- delete as;
- as = 0;
- human *asd = new Sanya((char*)"228", 13);
- asd->eat();
- printf("%d\n", asd->get_years());
- delete asd;
- asd = 0;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement