C++模板使用笔记-创新互联

模板的声明和定义分别在两个文件中,其中function.h内容为

站在用户的角度思考问题,与客户深入沟通,找到双滦网站设计与双滦网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站建设、成都网站设计、企业官网、英文网站、手机端网站、网站推广、域名注册网站空间、企业邮箱。业务覆盖双滦地区。
#ifndef _BC_FUNCTION_H_
#define _BC_FUNCTION_H_
templateT add(const T &a,const T &b);
templateT mul(const T& a,const T& b);
templateT div(const T& a,const T& b);
templateT sub(const T& a,const T& b);
#include "../src/function.cpp"
#endif

function.cpp内容为

#ifndef _FUNCTION_CPP_
#define _FUNCTION_CPP_
#include "../include/function.h"
templateT add(const T &a,const T &b)
{
    return a+b;
}
templateT mul(const T &a,const T &b)
{
    return a*b;
}
templateT div(const T& a,const T &b)
{
    return a/b;
}
templateT sub(const T &a,const T& b)
{
    return a-b;
}
#endif

如果定义类并且类中有static变量需要在类外初始化为

templateT* Foo::shared_resource_ = nullptr;

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


网页名称:C++模板使用笔记-创新互联
转载注明:http://lszwz.com/article/ghdjj.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款