0

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.

  • Please also show your cpp-files. Did you implement all methods? Besides that you dereference `render` and `physics` uninitialized, which will result in undefined behaviour. –  Feb 02 '14 at 23:29
  • You are also missing a bunch of `;` in `main` and `Class` needs to be lower case `class`. Several includes are also wrong, because they lack double quotes. I assume these are all typos, if this is the case please correct them. –  Feb 03 '14 at 01:20
  • Its not this I wrote this code in the question to simplify the code as i have quite few methods etc. so some typos are there as I said code compiles. I found a way around it so thanks for the help. About renderer etc. i just forgot to add in the question sorry for misleading you – user3264021 Feb 03 '14 at 02:29
  • @user3264021 - "I found a way around it" is not an acceptable answer. Please 1) Update your question with the exact error message (copy/paste the message). 2) Show the exact line of code giving the message. 3) Q: What is your compiler? And finally 4) What is your "way around it"? – FoggyDay Feb 03 '14 at 03:27

2 Answers2

1

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

FoggyDay
  • 11,962
  • 4
  • 34
  • 48
  • Im quite sure its not this it only happens when I try to pass physics from main to pixel class same happens with render. when i remove include code compiles just fine – user3264021 Feb 03 '14 at 00:56
  • Post the exact error message, and the corresponding line. It would also be helpful to know what compiler you're using. – FoggyDay Feb 03 '14 at 01:10
0

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

JonPall
  • 814
  • 4
  • 9