10.12hw

cpp 复制代码
#include <iostream>

using namespace std;
class Animal
{
private:
    string name;
public:
    Animal() {}
    Animal(string name):name(name){}
    virtual void perform()=0;
    void show()
    {
        cout << name << ":" ;
    }
};
template <typename T>
class Action:Animal
{
private:
    T action;
public:
    Action() {}
    Action(string name,T action):Animal(name),action(action)
    {}
    void perform()
    {
        Animal::show();
        cout << action << endl;
    }
};
int main()
{
    Action<string> a("dog","wang");
    Action<string> b("cat","miao");
    Action<string> c("cow","mou");
    a.perform();
    b.perform();
    c.perform();
    return 0;
}
相关推荐
北冥you鱼1 小时前
Go-Ethereum (Geth) 最佳实践:从部署到生产环境优化
开发语言·后端·golang
这不小天嘛8 小时前
JAVA八股——J集合篇
java·开发语言
AOwhisky8 小时前
Python 学习笔记(第一期与第二期)——基础语法——核心知识点自测与详解
开发语言·笔记·python·学习·云原生·运维开发
ysu_03148 小时前
05 | 持久化撤销提示非核心功能
算法·游戏程序
浮沉9879 小时前
二分查找算法概述&通用模板
算法
Keven_1110 小时前
算法札记:SPFA判负环算法的证明
算法
什巳10 小时前
JAVA练习278- 和为 K 的子数组
java·学习·算法·leetcode
喜欢的名字被抢了11 小时前
Python实战:SQLAlchemy ORM与FastAPI项目集成
开发语言·python·sql·教程·fastapi