- 论坛徽章:
- 0
|
本帖最后由 cppfans6 于 2012-10-05 12:18 编辑
回复 6# linux_c_py_php
为什么?我刚才试了,确实不行。
a.h文件:
#include <iostream>
using namespace std;
namespace nsa
{
template <class type>type max(type a,type b);
}
a.cpp文件:
#include "a.h"
namespace nsa
{
template <class type>type max(type a,type b)
{
return(a>b)?a:b;
}
}
主文件:
#include "a.h"
using namespace nsa;
int main()
{
cout<<"max(6,8)is:"<<nsa::max(6,8)<<endl;
return 0;
}
编译出现链接错误:
error LNK2001: unresolved external symbol "int __cdecl nsa::max(int,int)" (?max@nsa@@YAHHH@Z)
怎么回事? |
|