C++??????????????????
???????????? ???????[ 2016/1/18 10:08:21 ] ????????.NET ???????????
???????
??????C++?????????????“?????C”?????????????????????????????????????????????з??????????????STL??C++??????????????????????????C++????У??????OO???????????????????????????????????????????????????У????????template(???)??????????????????????????????????????У????????????????????????????У?????????
????????????????
???????????????
??????????????????
????????????
???????????????????????????????????????????????????????????????????????????????????е??????????????н???Щ?????????????????麯????????????????л??????д??Щ?????????????????е???幦??????????????????????????
class Animal
{
public :
virtual void shout() = 0;
};
class Dog :public Animal
{
public:
virtual void shout(){ cout << "?????"<<endl; }
};
class Cat :public Animal
{
public:
virtual void shout(){ cout << "????~"<<endl; }
};
class Bird : public Animal
{
public:
virtual void shout(){ cout << "???!"<<endl; }
};
int main()
{
Animal * anim1 = new Dog;
Animal * anim2 = new Cat;
Animal * anim3 = new Bird;
//???????????????????????????????????????????????????????????????????????????
anim1->shout();
anim2->shout();
anim3->shout();
//delete ????
...
return 0;
}
????????????????????????麯?????????????????????麯???????????????????????????麯???????????????????????麯??????麯?????д?????????麯??????????????????麯??????????麯?????????????麯????????????
??????????????????????????????????????????????
//?????и????????????????????
int main()
{
vector<Animal*>anims;
Animal * anim1 = new Dog;
Animal * anim2 = new Cat;
Animal * anim3 = new Bird;
Animal * anim4 = new Dog;
Animal * anim5 = new Cat;
Animal * anim6 = new Bird;
//????????????
anims.push_back(anim1);
anims.push_back(anim2);
anims.push_back(anim3);
anims.push_back(anim4);
anims.push_back(anim5);
anims.push_back(anim6);
for (auto & i : anims)
{
i->shout();
}
//delete????
//...
return 0;
}
???????????????????麯??????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11