0

問題の紹介: Windows 7 - 64 ビット OS で実行されているVisual Studio 2012のC++/DirectX11でレンダリング エンジン (32 ビット モードでコンパイル) に取り組んでいますが、奇妙なリンク エラーが発生します。私のクラス ( Entity3Dは、シーンの基本的な俳優のようなものです)。 すべてのバウンディング ボリューム クラスはShape3Dクラスから継承します。各エンティティにはShape3D * boundingVolume メンバがあり、初期化時に特定のシェイプ タイプに初期化されます。2 つのShape3Dの 間で衝突するとき、関数を介してそれらを渡します。関数はそれらのタイプをチェックします( SphereEntity

bool Intersect(Shape3D* a, Shape3D* b)/*Box*/Whatever) であり、型は関数ポインターの配列内の関数のインデックスである数値を表します。

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 *)" (?IntersectArray@Collision@Engine@@3PAY03P6ADPAVShape3D@12@0@ZA) already defined in Entity3D.obj
File Intersect.obj

Intersect.hはEntity3D.cpp にのみ含まれ、Entity3D.hには含まれず、 Entity3D.hに含まれるヘッダーにも含まれませEntity3D.cppにはEntity3D.hIntersect.hのみが含まれています。クリーンアップして再構築しましたが、エラーが続きます。Intersect(Shape3D a, Shape3D* b)* は、Entity3D.cppファイル内のEntity3Dの 1 つのメソッドでのみ呼び出されます。現在、プロジェクトに他のコンパイル エラーや警告はありません。他に何がそのような問題を引き起こす可能性がありますか?

4

1 に答える 1

0

問題を修正しました。IntersectArrayの定義を Intersect.cpp ファイルに移動しました。今のところ必要な場所はそこだけなので。

于 2013-03-27T21:00:50.827 に答える