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;
}
相关推荐
CoderCodingNo13 分钟前
【GESP】C++七级考试大纲知识点梳理, (1) 数学库常用函数
开发语言·c++
老鱼说AI31 分钟前
CUDA架构与高性能程序设计:异构数据并行计算
开发语言·c++·人工智能·算法·架构·cuda
罗湖老棍子1 小时前
【例 1】数列操作(信息学奥赛一本通- P1535)
数据结构·算法·树状数组·单点修改 区间查询
big_rabbit05021 小时前
[算法][力扣222]完全二叉树的节点个数
数据结构·算法·leetcode
子超兄2 小时前
线程池相关问题
java·开发语言
张李浩2 小时前
Leetcode 15三题之和
算法·leetcode·职场和发展
dinl_vin3 小时前
python:常用的基础工具包
开发语言·python
2301_793804693 小时前
C++中的适配器模式变体
开发语言·c++·算法
x_xbx3 小时前
LeetCode:206. 反转链表
算法·leetcode·链表
abant23 小时前
leetcode 138 复制随机链表
算法·leetcode·链表