2013-03-27 47 views
0

好一点引入问题“已经定义”:我在的Visual Studio 2012运行工作的一个渲染引擎(在32位模式下进行编译)的C++/DirectX11的Windows 7 - 64位操作系统,我有一个奇怪的链接错误出现在我的Entity类(实体3D就像场景的基本演员)。
我所有的边界体类从了Shape3D class.Each实体继承有了Shape3D *它包围体成员,被初始化为在初始化时特定的形状类型。
当两个了Shape3D的之间碰撞我将它们传递槽的功能 - bool Intersect(Shape3D* a, Shape3D* b)函数然后检查它们的类型(球体/*箱* /无论)和类型表示数这是一个索引功能函数指针数组:LNK2005函数指针阵列中的obj

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

所以它就像一个虚拟的调度。确定这样的InersectArray是功能的阵列(在Intersect.h声明),这就是给我的链接错误:

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 *)" ([email protected]@[email protected]@[email protected]@[email protected]) already defined in Entity3D.obj 
File Intersect.obj 

Intersect.h只有列入Entity3D.cpp,它不包含在Entity3D.h中,也不包括在Entity3D.h包含的任何头文件中。 Entity3D.cpp只包含实体3D.hIntersect.h。我清理并重建,错误仍然存​​在。 Intersect(Shape3D a,Shape3D * b)*仅在Entity3DEntity3D.cpp文件中的一种方法中被调用。项目中目前没有其他编译错误或警告。还有什么可能导致这样的问题?

+1

你的头文件中有#pragma once或#ifndef吗?看起来并不重要,但只是双重检查。 – IdeaHat 2013-03-27 20:45:19

+0

是的,每个头文件都有'#pragma once'和'#ifndef'包含后卫 – 2013-03-27 20:46:38

+1

什么是'Intersect.lib'? – 2013-03-27 20:49:18

回答

0

修正这个问题,我刚搬来的定义IntersectArrayIntersect.cpp文件,因为现在这就是它唯一需要的地方。

+1

这告诉我们你断言'intersect.h'只包含在一个源中是不正确的。 – 2013-03-27 21:21:17