5
I'm getting an "unresolved external symbol "public:__thiscall hijo<int>::hijo<int>(void)" referenced in function_main
我开始了一个新的项目,因为我在另一个更大的项目上遇到了同样的错误。 当我尝试使用new关键字分配空间时发生错误。 如果这个错误是愚蠢的,请原谅我,因为我在过去的几个月里没有编程任何东西。使用模板类时链接器错误?
/********************file hijo.h******************/
#pragma once
#ifndef hijo_h
#define hijo_h
template <class A>
class hijo
{
public:
hijo(void);
~hijo(void);
};
#endif
/********************file hijo.cpp***************/
#include "hijo.h"
#include <iostream>
using namespace std;
template <class A>
hijo<A>::hijo(void)
{
}
template <class A>
hijo<A>::~hijo(void)
{
}
/*********************at main() function ***************/
#include <iostream>
#include "hijo.h"
int main(){
hijo<int> *h = new hijo<int>; <---- PROBLEM AT THIS LINE
system("pause");
return 0;
}
“但不幸的是它留在这里” - 直到我们获得模块。 \ *穿过手指* – Xeo 2012-02-07 05:43:51
工作就像一个魅力,只需要对您的解决方案做一点修复。 而不是添加.h文件中的代码,我只是将.cpp文件包含在.h文件的底部。 这就好像两个部分都在同一个文件中一样。 在 “hijo.cpp” 的#ifndef hijo_cpp 的#define hijo_cpp 并在底部 #ENDIF ... 感谢ü的回答... – HoNgOuRu 2012-02-07 05:44:29
得等到8分多钟,以纪念这个问题作为回答 – HoNgOuRu 2012-02-07 05:45:52