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;
}
相关推荐
9***P3341 小时前
PHP代码覆盖率
开发语言·php·代码覆盖率
CoderYanger1 小时前
优选算法-栈:67.基本计算器Ⅱ
java·开发语言·算法·leetcode·职场和发展·1024程序员节
jllllyuz1 小时前
Matlab实现基于Matrix Pencil算法实现声源信号角度和时间估计
开发语言·算法·matlab
稚辉君.MCA_P8_Java1 小时前
DeepSeek 插入排序
linux·后端·算法·架构·排序算法
多多*1 小时前
Java复习 操作系统原理 计算机网络相关 2025年11月23日
java·开发语言·网络·算法·spring·microsoft·maven
凌康ACG1 小时前
Sciter之c++与前端交互(五)
c++·sciter
p***43482 小时前
Rust网络编程模型
开发语言·网络·rust
ᐇ9592 小时前
Java集合框架深度实战:构建智能教育管理与娱乐系统
java·开发语言·娱乐
梁正雄2 小时前
1、python基础语法
开发语言·python
.YM.Z3 小时前
【数据结构】:排序(一)
数据结构·算法·排序算法