LNK2019:函数"函数"中'symbol'引用未解析的外部符号;致命错误 LNK1120:1 未解析的外部
LNK2019: unresolved external symbol 'symbol' referenced in function 'function'; fatal error LNK1120: 1 Unresolved external
嗨,我做了一个简单的C++程序,但我遇到了错误,我不知道我做错了什么。我是C++语法的新手,所以我不知道我犯了什么错误导致了所述的链接器错误。以下是生成此错误的示例代码:
ITest.h
#ifndef ITest_H
#define ITest_H
//#[ ignore
#ifdef _MSC_VER
// disable Microsoft compiler warning (debug information truncated)
#pragma warning(disable: 4786)
#endif
//#]
//## auto_generated
#include <string>
//## auto_generated
#include <algorithm>
//## auto_generated
//## link itsNmNeighborhoodEntry
class NmNeighborhoodEntry;
//## class ITest
class ITest {
//#[ ignore
//// Constructors and destructors ////
public :
//## auto_generated
virtual ~ITest();
//// Relations and components ////
protected :
NmNeighborhoodEntry* itsNmNeighborhoodEntry; //## link itsNmNeighborhoodEntry
};
#endif
ITest.cpp
//## auto_generated
#include "ITest.h"
//## link itsNmNeighborhoodEntry
#include "NmNeighborhoodEntry.h"
//## class ITest
ITest::~ITest() {
}
测试1.h
#ifndef Test1_H
#define Test1_H
//#[ ignore
#ifdef _MSC_VER
// disable Microsoft compiler warning (debug information truncated)
#pragma warning(disable: 4786)
#endif
//#]
//## auto_generated
#include <string>
//## auto_generated
#include <algorithm>
//## class Test1
#include "ITest.h"
//## auto_generated
class NmNeighborhoodEntry;
//## class Test1
class Test1 : public ITest {
//#[ ignore
// Default Constructor is Private
public:
Test1();
// Default Copy Constructor is Private
private:
Test1(const Test1& self);
// Default Assignment Operator is Private
private:
Test1& operator=(const Test1& aTest1);
//#]
//// Constructors and destructors ////
public :
//## auto_generated
~Test1();
NmNeighborhoodEntry* getNmNeighborhoodEntry();
};
#endif
Test1.cpp
//## auto_generated
#include "Test1.h"
//## auto_generated
#include "NmNeighborhoodEntry.h"
NmNeighborhoodEntry* itsNmNeighborhoodEntry;
//## class Test1
Test1::~Test1() {
}
Test1::Test1() {
}
NmNeighborhoodEntry* getNmNeighborhoodEntry() {
//return itsNmNeighborhoodEntry;
return NULL;
}
NmNeighborhoodEntry.h
#ifndef NmNeighborhoodEntry_H
#define NmNeighborhoodEntry_H
//#[ ignore
#ifdef _MSC_VER
// disable Microsoft compiler warning (debug information truncated)
#pragma warning(disable: 4786)
#endif
//#]
//## auto_generated
#include <string>
//## auto_generated
#include <algorithm>
//## class NmNeighborhoodEntry
class NmNeighborhoodEntry {
//#[ ignore
// Default Constructor is Private
private:
NmNeighborhoodEntry();
// Default Copy Constructor is Private
private:
NmNeighborhoodEntry(const NmNeighborhoodEntry& self);
// Default Assignment Operator is Private
private:
NmNeighborhoodEntry& operator=(const NmNeighborhoodEntry& aNmNeighborhoodEntry);
//#]
//// Constructors and destructors ////
public :
//## auto_generated
~NmNeighborhoodEntry();
bool myIsPending; //## attribute myIsPending
unsigned short index; //## attribute myNodeIndex
};
#endif
NmNeighborhoodEntry.cpp
//## auto_generated
#include "NmNeighborhoodEntry.h"
//## class NmNeighborhoodEntry
NmNeighborhoodEntry::~NmNeighborhoodEntry() {
}
驱动程序.cpp
//#include "ITest.h"
#include "Test1.h"
//#include "Test2.h"
#include "NmNeighborhoodEntry.h"
Test1 *test1;
//Test2 *test2;
NmNeighborhoodEntry* myNmNeighborhoodEntry;
void main() {
test1 = new Test1;
//test2 = new Test2;
//test1->itsNmNeighborhoodEntry = NULL;
myNmNeighborhoodEntry = test1->getNmNeighborhoodEntry();
}
您得到的错误消息表示未定义引用的"symbol"。它还告诉你在哪个"函数"中引用了"符号"。
您可能在某个地方缺少函数或方法实现。
编辑:
NmNeighborhoodEntry* getNmNeighborhoodEntry() {
//return itsNmNeighborhoodEntry;
return NULL;
}
这是您的错误;它需要有这样的类名来限定它。
NmNeighborhoodEntry* Test1::getNmNeighborhoodEntry() {
//return itsNmNeighborhoodEntry;
return NULL;
}
执行此操作的方式声明了一个全局函数。您需要在函数名称之前有Test1::,以向编译器指示这是类Test1的方法的实现。
相关文章:
- 在函数内创建的对象的范围 - 如果在函数外部存储和访问引用,它们是否有效?
- C++指针无法在函数外部传递值和分段错误(核心转储)错误
- C++:函数外部的超时功能
- 如何在函数外部访问函数中局部变量的值?
- 在成员函数外部封闭类的定义中需要默认成员初始值设定项
- 以延长构造函数外部 QT 对象的生存期
- 全局静态变量不"staying defined"函数外部
- C++ 函数外部丢失的指针对象
- 向量大小在构造函数外部恢复为 0
- 删除函数外部的实例化对象
- 在函数外部编写代码
- 为什么我不能添加到方法/函数外部的 ostringstream
- 用于在方法或函数外部声明的变量的内存
- SDL2 在函数外部加载字体会引发错误
- 如何在具有多态性的函数外部创建对象
- 在函数外部声明对象,将其作为引用传递,然后在函数内部创建它
- 向量未在函数C++外部更新
- 访问函数外部的堆栈对象
- 在c++中访问函数外部的数组
- 如何更新函数外部的数组(指向指针)