home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
borllexp
/
blx_1_2
/
pets.cpp
next >
Wrap
Text File
|
1991-05-02
|
649b
|
34 lines
// PETS.CPP : Conversations with your animals
#include <stdio.h>
struct pet {
virtual void speak() {} // function definition
};
struct dog : pet {
void speak() { puts("Bark!"); }
};
struct cat : pet {
void speak() { puts("Meow!"); }
};
struct bird : pet {
void speak() { puts("Tweet!"); }
};
struct goldfish : pet {
void speak() { puts("!"); }
};
// aggregate initialization of menagerie
pet* menagerie[] = { new dog, new cat, new bird };
const int sz = sizeof(menagerie)/sizeof(menagerie[0]);
void main(void)
{
for (int i = 0; i < sz; i++)
menagerie[i]->speak();
}