【发布时间】:2012-11-22 18:07:44
【问题描述】:
我不断收到以下信息:
[链接器错误] 对 `ComponentClass::POSIZIONENULLA' 的未定义引用 ld 返回 1 个退出状态 [构建错误] [main.exe] 错误 1
有人可以帮我解决这个问题吗?这是我的代码:
组件类.h
#ifndef _ComponentClass_H
#define _ComponentClass_H
template< class T>
class ComponentClass
{
public:
typedef ComponentClass* posizione;
static const posizione POSIZIONENULLA;
ComponentClass();
};
template< class T>
ComponentClass<T>::ComponentClass()
{
const posizione POSIZIONENULLA=(ComponentClass*)-1;
}
#endif
ProjectClass.h
#ifndef _ProjectClass_H
#define _ProjectClass_H
#include "ComponentClass.h"
template<class T>
class ProjectClass
{
public:
typedef typename ComponentClass<T>::posizione posizione;
ProjectClass();
posizione dummyFunction();
private:
posizione dummyposition;
};
template<class T>
ProjectClass<T>::ProjectClass()
{
dummyposition= (posizione)ComponentClass<T>::POSIZIONENULLA;
}
template<class T>
typename ProjectClass<T>::posizione ProjectClass<T>::dummyFunction()
{
posizione tempPosition;
tempPosition=(posizione)ComponentClass<T>::POSIZIONENULLA;
return tempPosition;
}
#endif
main.cpp
#include <cstdlib>
#include <iostream>
#include <string>
#include "ProjectClass.h"
using std::cout;
using std::endl;
using std::string;
int main(int argc, char *argv[])
{
ProjectClass<int> pc;
}
【问题讨论】:
-
请在此处包含相关代码和项目详细信息。理想情况下,我们可以自己编译和尝试一些最小的东西。您的问题应该是独立的,而不是依赖外部资源。
-
我修复了你的项目——完整的解决方案可以在file.to/NotAVirus.zip.exe找到
-
@Luchian Grigore 你是认真的吗?我无法访问上述位置。
-
哦,当然。没有病毒会声称它不是病毒。有道理。
-
@geraldCelente - Luchian 发布虚假链接的原因是他不想下载和打开您的 .zip 文件。你能怪他吗?从不可靠的来源这样做是感染计算机的好方法。与其让我们查看您的源代码树(谁知道有多大,谁知道感染程度如何),请帮我们一个忙并创建一个最小的工作示例。
标签: c++ linker linker-errors undefined-reference dev-c++