????????????
?????????????????????????????????????????????????????????????????????渭??貌???????????????谓???????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????写?:
class Animal
{
public :
void shout() { cout << "????????????" << endl; };
};
class Dog
{
public:
void shout(){ cout << "?????"<<endl; }
};
class Cat
{
public:
void shout(){ cout << "????~"<<endl; }
};
class Bird
{
public:
void shout(){ cout << "???!"<<endl; }
};
template <typename T>
void  animalShout(T & t)
{
t.shout();
}
int main()
{
Animal anim;
Dog dog;
Cat cat;
Bird bird;
animalShout(anim);
animalShout(dog);
animalShout(cat);
animalShout(bird);
getchar();
}
??????????????????????t.shout()??????????????????????????????????????????????????????????shout??????????????????????????????貌?????????????????????????????????????????????????????????????????????????谩?
?????????????????????????????
???????????????
????OO???????????????????????????????
??????????????????????渭??????????
???????????????
???????????????楹�?????????????????锌?????
???????????胁?危?????????????????胁?巍?
?????????楹�????????????????????????????????楹�???????????
???????????????????????????????????楹�????????????????????????????????????????????械??????
???????????????
????????????????????????C++??蟹???????STL???????????????
???????????????????????????效???
???????泻???????????????????????????????????????????????????????
???????????????
???????????????????????????????
????????????????????????????????????????小??
?????????????????????
??????????????????????
??????谓??????????????胁???卸??????????????????????????????????????????????????????????.????????????????????????
????void AnimalShot(Animal & anim)
????{
????anim.shout();
????}
?????????shout??????????????????????械????????????
?????????????????????????????????????效?????????纾�
????template <typename T>
????void AnimalShot(T & anim)
????{
????anim.shout();
????}
????????anim??????????????????????????????????anim??????????????????????????????校?T???????shout()?????????shout??T????????????