好一點引入問題「已經定義」:我在的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.h和Intersect.h。我清理並重建,錯誤仍然存在。 Intersect(Shape3D a,Shape3D * b)*僅在Entity3D的Entity3D.cpp文件中的一種方法中被調用。項目中目前沒有其他編譯錯誤或警告。還有什麼可能導致這樣的問題?
你的頭文件中有#pragma once或#ifndef嗎?看起來並不重要,但只是雙重檢查。 – IdeaHat 2013-03-27 20:45:19
是的,每個頭文件都有'#pragma once'和'#ifndef'包含後衛 – 2013-03-27 20:46:38
什麼是'Intersect.lib'? – 2013-03-27 20:49:18