Linux C/C++ 模板:成员模板

一、代码

        成员模板:一个自身是模板的成员。

#include <iostream>
#include <typeinfo>
using namespace std;

//成员模板
template <typename T>
class Array
{
public:
        template <typename T1>
        void output(T thistype, T1 othertype);
};

//成员模板
template <typename T>
template <typename T1>
void Array<T>::output(T thistype, T1 othertype)
{
        cout<<"thistype is "<<typeid(thistype).name()<<", othertype is "<<typeid(othertype).name()<<endl;
}

int main(int argc, char*argv[])
{
        Array<int> arr;
        arr.output(10, "hello world");
        arr.output(20, 8.8);
        arr.output(30, false);

        return 0;
}

二、输出结果

        不同编译器typeid().name()返回的结果不同。

        Linux gcc下输出结果:


        Windows VS下输出结果:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值