c++ - 错误 LNK2019 : unresolved external symbol classes

标签 c++

当我从 main 调用 new TerrainClass() 时出现以下错误,尝试了几个小时来修复它,请帮忙。

error LNK2019: unresolved external symbol "public: __thiscall TerrainClass::TerrainClass(void)" (??0TerrainClass@@QAE@XZ) referenced in function "void __cdecl init(void)" (?init@@YAXXZ)

GLDrawObject.h

#pragma once

class GLDrawObject
{

};

地形.cpp

#pragma once

TerrainClass::TerrainClass() : GLDrawObject()
{

}

地形.h

#pragma once

#include "GLDrawObject.h"

class TerrainClass : public GLDrawObject
{
public: 
    TerrainClass();
};

最佳答案

首先,您的 Terrain.cpp 应该如下所示:

#include "Terrain.h"

TerrainClass::TerrainClass() : GLDrawObject()
{

}

其次,您遇到的是链接器错误,而不是编译器错误;编译后,您需要将 Terrain.o 与其余目标文件链接起来。

关于c++ - 错误 LNK2019 : unresolved external symbol classes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34992162/

相关文章:

c++ - 将基类动态转换为派生对象

c++ - 为什么这个插槽被调用两次?

C++ 当前系统时间(以纳秒为单位)作为长整数以发送 influxdb

c++ - 是否可以在 C++ 中获取函数参数的默认值?

c++ - 深度优先搜索

c++ - 静态内存中的STL结构 'Losing' 跨线程数据

c++ - 虚函数错误?

C++ 文本文件不会保存在 Unicode 中,它一直保存在 ANSI 中

c++ - 在C++中判断一个int是否被赋值有什么优雅的方法吗?

c++ - 在 C++ 中发生堆栈溢出时获取 SIGSEGV