C++ 模块化编程 笔记

//***********文件 head_name.hpp ********************
///head_name.hpp 头文件

#ifndef __HEAD_NAME_HPP__
#define __HEAD_NAME_HPP__
#define DLLAPI __declspec(dllexport)

//
 #ifdef __cplusplus
extern "C" {

#endif

..................// C函数代码,名字不改编

#ifdef __cplusplus
}
#endif
/

 namespace nsps  //定义名字空间
{
...//C++  代码

template<typename _Tp> class DLLAPI TPoint
{
public:
…//dosomething

_Tp fun(_Tp);
...
};
class DLLAPI Complex
{
public:
Complex():real(0),img(0){}
Complex(double _real, double _img):real(_real),img(_img){}
…//dosomethingComplex operator +(Complex c);private:double real;double img;};
 }

#include"fun.hpp" //模板类实现代码
#endif



//***********文件 fun.hpp ********************
// fun.hpp文件,将模板类的实现放在fun.hpp中 ,在编译好的dll文件输出函数表中,不会有nsps::TPoint<_Tp>::fun(_Tp)函数,这是模板相对非模板的区别。

#ifndef __FUN_HPP__
#define __FUN_HPP__

template<typename _Tp> _Tp  nsps::TPoint<_Tp>::fun(_Tp)

{
…//dosomething

}

#endif






//***********文件 complex.cpp ********************
//complex.cpp 文件,在编译好的dll文件输出函数表中,有该类中成员函数,构造函数的料峭身影,不过名字被改编。cpp->obj->dll(exe)

#include"head_name.hpp"

Complex nsps::Complex::operator +(Complex c)
{
return Complex(this->real+c->real,this->img+c->img);

}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值