LNK2001 に問題があります: 未解決の外部シンボル エラーです。名前空間にすべてのクラスがあり、複数のファイルを使用するグローバル変数を参照している場合にのみ表示されます。これが私のコードがどのように見えるかのサンプルコードです:
エンジン.h
#pragma once
namespace Engine{
#include "Core.h"
#include "Display.h"
#include "Box.h"
// ... some code...
}
using namespace Engine;
Core.cpp
#include "Engine.h"
// ...some code...
コア.h
extern Matrix matrix;
// ... some code...
ディスプレイ.cpp
#include "Engine.h"
Matrix matrix;
// ... some code...
Display.h
// ... some code...
Box.cpp
void Box::draw(PxShape *shape){
// matrix=.. some code...
}
Box.h
// ... some code...
エラーメッセージ
1>Box.obj: エラー LNK2001: 未解決の外部シンボル "struct Engine::Matrix Engine::matrix" (?matrix@Engine@@3UMatrix@1@A)
名前空間にコメントすると、すべてが正常に機能します。名前空間を使用したいのは初めてで、これをどうするかわかりません。