Pergunta

Ok a little introduction into the issue: I'm working on a rendering engine(compiling in 32 bit mode) in C++/DirectX11 in Visual Studio 2012 running on Windows 7 - 64 bit OS and I have a strange link error that comes up in my Entity class (the Entity3D is like the basic actor of the scene).
All of my bounding volume classes inherit from a Shape3D class.Each Entity has a Shape3D* boundingVolume member in it, that is initialized to a specific shape type at initialization time.
When colliding between two Shape3D's I pass them trough a function - bool Intersect(Shape3D* a, Shape3D* b) the function then checks their types(Sphere/*Box*/Whatever) and the type represents a number which is the index of a function in an array of function pointers:

bool(*IntersectArray[4][4])(Shape3D* a, Shape3D* b) = 
{
    {
        IntersectSphereSphere,
        IntersectSphereBox,
        IntersectSphereOrientedBox,
        IntersectSphereFrustum,
    },
    {
        IntersectBoxSphere,
        IntersectBoxBox,
        IntersectBoxOrientedBox,
        IntersectBoxFrustum
    },
    {
        IntersectOrientedBoxSphere,
        IntersectOrientedBoxBox,
        IntersectOrientedBoxOrientedBox,
        IntersectOrientedBoxFrustum
    },
    {
        IntersectFrustumSphere,
        IntersectFrustumBox,
        IntersectFrustumOrientedBox,
        IntersectFrustumFrustum
    }
};

So it's like a virtual dispatch. Ok so the InersectArray is the array of the functions(declared in Intersect.h) and that's what gives me the link error:

error LNK1169: one or more multiply defined symbols found
error LNK2005: "char (__cdecl*(* Engine::Collision::IntersectArray)[4])(class Engine::Collision::Shape3D *,class Engine::Collision::Shape3D *)" (?IntersectArray@Collision@Engine@@3PAY03P6ADPAVShape3D@12@0@ZA) already defined in Entity3D.obj
File Intersect.obj

Intersect.h is only included in Entity3D.cpp, it's no included in Entity3D.h, nor in any of the headers that Entity3D.h includes.Entity3D.cpp only includes Entity3D.h and Intersect.h.I cleaned and rebuilt, error persists.Intersect(Shape3D a, Shape3D* b)* is called only in one method of Entity3D in the Entity3D.cpp file. There are no other compile errors or warnings currently in the project. What else could cause such an issue?

Foi útil?

Solução

Fixed the issue, I just moved the definition of IntersectArray in the Intersect.cpp file, since for now that's the only place it's needed.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top