간단히하기 위해 두 개의 DLL_TUTORIAL.dll을 헤더 MathFuncsDll.h에 루트 폴더 C : \에 넣었습니다. \ DLL_TUTORIAL :지연로드 DLL
그런 다음
구성 속성 -> 링커 -> 입력 -> 지연의 DLL의
에 C 부하 설정 빈 프로젝트를 생성 .dll; % (DelayLoadDLLs)
및
구성 속성 -> VC++ 디렉토리 -이> 포함 디렉토리
C에 : \; $ (IncludePath)
컴파일러 명령 :
/Zi/nologo/W3/WX-/O2/Oi-/GL/D "_MBCS"/ Gm-/EHsc/MT/GS /Gy/fp : 정밀도/Zc : wchar_t/Zc : forScope /Fp"Release\clean_rough_draft.pch "/ 빠"릴리스 \ "/ FO"릴리스 \ " /Fd"Release\vc100.pdb"/ 하나님/analyze-/errorReport : 큐
이 프로젝트 main이있는 파일 만 포함합니다.
MAIN.CPP
#include <Windows.h>
#include <iostream>
#include "MathFuncsDll.h"
using namespace MathFuncs;
using namespace std;
int main()
{
std::cout<< MyMathFuncs<int>::Add(5,10)<<endl;
system("Pause");
return 0;
}
의 DLL은 다른 솔루션에서 성공적으로 운영되고 있습니다. 이러한 기능
MathFuncsDll.h
namespace MathFuncs
{
template <typename Type>
class MyMathFuncs
{
public:
static __declspec(dllexport) Type Add(Type a, Type b);
static __declspec(dllexport) Type Subtract(Type a, Type b);
static __declspec(dllexport) Type Multiply(Type a, Type b);
static __declspec(dllexport) Type Divide(Type a, Type b);
};
}
설명 :
#include "MathFuncsDll.h"
#include <stdexcept>
using namespace std;
namespace MathFuncs
{
template <typename Type>
Type MyMathFuncs<Type>::Add(Type a,Type b)
{ return a+b; }
template <typename Type>
Type MyMathFuncs<Type>::Subtract(Type a,Type b)
{ return a-b; }
template <typename Type>
Type MyMathFuncs<Type>::Multiply(Type a,Type b)
{ return a*b; }
template <typename Type>
Type MyMathFuncs<Type>::Divide(Type a,Type b)
{
if(b == 0) throw new invalid_argument("Denominator cannot be zero!");
return a/b;
}
}
이 프로그램 실행이 실패
1> main.obj : 오류 LNK2001 :되지 않은 외부 기호 " public : static int __cdecl MathFuncs :: MyMathFuncs :: Add (int, int) "? @? $ MyMathFuncs @ H @ MathFuncs @@ SAHHH @ Z),210 1> C : \ 사용자 메크 \ 문서가 프로젝트 \ 비주얼 스튜디오 2010 \ \ \ clean_rough_draft \ clean_rough_draft.exe 릴리스 \ : 치명적인 오류 LNK1120 : 1 개 확인되지 않은 외부 내 실수를 지적 할 수
?
템플릿 방법 내보내기가 지원되지 않습니다. .h 파일에 넣어야 할 것이다. 빈 DLL을 남겨 둡니다. –
정교하게 말하면, 템플릿 메소드는 "실제"메소드가 아닙니다. 템플릿 메소드는 컴파일 타임에 메소드를 생성하는 데 사용되는 금형입니다. 따라서 템플릿 메소드는 객체 코드로 컴파일되지 않습니다. – nakiya