简体   繁体   English

C ++无法解析的外部

[英]C++ unresolved externals

im writing a game and I have a problem resulting "C++ unresolved externals" 我正在写游戏,但遇到了导致“ C ++无法解析的外部条件”的问题

** My Classes:** ** 我的课程:**

Terrain.h Terrain.h

Class Terrain
{};

PhysicsObject.h PhysicsObject.h

Class PhysicsObject
{};

Physics.h Physics.h

#include PhysicsObject
Class Physics : public PhysicsObject
{
public:
    Physics();
    void add(PhysicsObject* o);
    void remove(PhysicsObject* o);
};

RenderObject.h RenderObject.h

Class RenderObject
{};

Render.h Render.h

#include RenderObject.h
Class Render: public RenderObject
{
public:
Render();
void add(RenderObject* o);
void remove(RenderObject* o);
};

Pixel.h Pixel.h

#include "PhysicsObject.h"
#include "RenderObject.h"

class pixel : public RenderObject, public PhysicsObject
{};

main.cpp main.cpp中

 #include "Physics.h"
 #include "Render.h"
 #include "Terrain.h"
 #include "Pixel.h"

void main()
{
    Physics* physics
    Render* render
    Terrain* terrain

    Pixel* pixel1 = new Pixel()

    renderer->add(pixel1);
    physics->add(pixel1);
}

I have a method in my main that will create pixels and store them in vectors inside of the render and physics. 我的主体中有一个方法可以创建像素并将其存储在渲染和物理场中的矢量中。 My problem is I need access to physics, terrain and render inside of the pixel so that my pixels can handle their collision and destruction on their own and remove themselves from the render and physics vectors. 我的问题是我需要访问像素内部的物理,地形和渲染,以便我的像素可以自行处理其碰撞和破坏,并从渲染和物理矢量中将其删除。

Any ideas how can I achieve that as when I tried to do it im getting C++ unresolved externals when I pass the pointers to the Pixel class. 任何想法都可以实现,就像我尝试将指针传递给Pixel类时获得C ++无法解析的外部函数一样。 Its possible that some classes are being called before they are created by complier but I don't know how to fix this. 在编译器创建某些类之前可能会调用它们,但我不知道如何解决。

"Unresolved externals" is a LINK TIME error. “外部问题未解决”是LINK TIME错误。 In general, all you have to do is make sure you have compiled all your source, and included all your libraries, before you build the .exe. 通常,您要做的就是在构建.exe之前确保已编译所有源代码并包括所有库。

If you're using MSVC++, for example, make sure your project includes terrain.cpp, PhysicsObject.cpp, etc. The same applies for any other IDE or Makefile you're using to build your project. 例如,如果您使用的是MSVC ++,请确保您的项目包括terrain.cpp,PhysicsObject.cpp等。这同样适用于您用于构建项目的任何其他IDE或Makefile。

"Unresolved externals" can also be seen as the compiler has seen declarations, but not the definitions. “未解决的外部条件”也可以视为编译器看到了声明,但没有看到定义。 Meaning it can't find your .cpp files. 这意味着它找不到您的.cpp文件。

Are they belonging to another project, and you've got a new one set up? 他们属于另一个项目,并且您已经设置了一个新项目吗? If so, drag and drop them from file explorer to the Source "folder" in VS. 如果是这样,请将其从文件资源管理器拖放到VS中的“源”文件夹中。 You can click a file and see it's relative path in the properties in VS btw. 您可以单击一个文件,然后在VS btw的属性中查看它的相对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM