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;
}
相关推荐
129Lab1 分钟前
BMS 核心算法:SOC 估算从安时积分到 LSTM-UKF 串级融合的 30 年演进(附 Python 实现)
python·算法·lstm·python3.11·bms·soc估算
kgkg2 分钟前
我通过逆向学到了douyin的美颜算法
算法
anew___20 分钟前
《从零手写操作系统 (30):环境变量与进程上下文——export/unset与继承语义》
java·开发语言·网络·jvm·算法
Cx330❀23 分钟前
Qt 多线程深度解析:从底层原理到 UI 线程与同步实战
开发语言·qt·ui·搜索引擎·性能优化·图形渲染
垆边人似月.31 分钟前
城市连通性(200分 / 并查集)
数据结构·算法·图论
西西弗Sisyphus35 分钟前
Qt6 实现 会动的界面像物理世界一样
c++·qt
谢亮_vipxieliang41 分钟前
Go GMP调度模型——从原理到实战的完整指南
开发语言·网络·golang
UIU11443 分钟前
头文件可以防什么错?运用头文件做声明
c++·学习·c#
Gust of wind1 小时前
串与KMP模式匹配:存储结构、基本操作、next数组手算
c语言·数据结构·后端·算法
Navigator_Z1 小时前
LeetCode //C - 1283. Find the Smallest Divisor Given a Threshold
c语言·算法·leetcode