//***********文件 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);
}
C++ 模块化编程 笔记
最新推荐文章于 2024-06-29 20:53:14 发布