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;
}
相关推荐
大侠归来6 小时前
C 语言 | 在函数中操作数组
c语言·c++·算法
liangshanbo12156 小时前
JavaScript 面试题:Object.keys() 的返回顺序是无序的吗?
开发语言·javascript·ecmascript
怕浪猫11 小时前
GEO 优化到底是什么?AI时代内容创作者必须懂的新技能
算法·面试·github
朝朝辞暮i12 小时前
C++ 第 23 课:class —— 开始真正进入面向对象
开发语言·c++·算法
Evand J13 小时前
【MATLAB例程】三维RRT+APF避障路径规划与到达角(AOA)定位算法|三维路径优化与定位仿真例程
算法·matlab·路径规划·代码·定位·rrt·aoa
小师兄吃牛肉13 小时前
C语言篇:宏
c语言·开发语言
郑同学的笔记13 小时前
【c++随笔28】strcmp 和 memcmp对比
开发语言·c++
随意起个昵称13 小时前
【背包dp】输出方案路径
c++·动态规划
言乐614 小时前
Python根据无法识别搜索词找出可能输入内容模型
开发语言·python·django·virtualenv·pygame
weixin_3077791314 小时前
有限产能智能排产与动态重排智能体:从需求解构到技术实现
开发语言·人工智能·算法·架构