简体   繁体   中英

C++ unresolved externals

im writing a game and I have a problem resulting "C++ unresolved externals"

** My Classes:**

Terrain.h

Class Terrain
{};

PhysicsObject.h

Class PhysicsObject
{};

Physics.h

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

RenderObject.h

Class RenderObject
{};

Render.h

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

Pixel.h

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

class pixel : public RenderObject, public PhysicsObject
{};

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. 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. 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.

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.

"Unresolved externals" can also be seen as the compiler has seen declarations, but not the definitions. Meaning it can't find your .cpp files.

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. You can click a file and see it's relative path in the properties in VS btw.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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