私はここ数年C#コーディングに甘んじてきましたが、今はC ++に戻って、単純なはずの問題に問題があることに気づきました。DarkGDK(dbのプレフィックスが付いたコマンド)と呼ばれるgamedev用のサードパーティライブラリを使用していますが、DGDKは問題ではありません。
これが私のコードです:
System.h
#pragma once
#include <string>
#include <map>
#include "DarkGDK.h"
using namespace std;
class System
{
public:
System();
~System();
void Initialize();
static void LoadImage(string fileName, string id);
static int GetImage(string id);
private:
map<string, int> m_images;
};
System.cpp
#include "System.h"
System::System()
{
}
System::~System()
{
}
void System::Initialize()
{
dbSetDisplayMode (1024, 640, 32);
dbSetWindowTitle ("the Laboratory");
dbSetWindowPosition(100, 10);
dbSyncOn ();
dbSyncRate (60);
dbRandomize(dbTimer());
}
void System::LoadImage(string fileName, string id)
{
int i = 1;
while (dbImageExist(i))
{
i++;
}
dbLoadImage(const_cast<char*>(fileName.c_str()), i, 1);
m_images[id] = i;
}
int System::GetImage(string id)
{
return m_images[id];
}
ここでの考え方は、文字列を整数値に対してマップするマップを作成し、ハードコードされた値の代わりに文字列を使用して画像にアクセスすることです。このクラスは実行されないため、画像のアンロードなどは処理されません。Systemのインスタンスを渡さずに画像メソッドにアクセスしたいので、staticを使用しました。
今、私はこのエラーを受け取ります:
blahblah \ system.cpp(39):エラーC2677:バイナリ'[':タイプ'std :: string'をとるグローバル演算子が見つかりません(または受け入れ可能な変換がありません)
マップを静的に変更すると、次のリンカーエラーが発生します。
1> System.obj:エラーLNK2001:未解決の外部シンボル "プライベート:静的クラスstd :: map、class std :: allocator>、int、struct std :: less、class std :: allocator >>、class std :: allocator 、class std :: allocator> const、int >>> System :: m_images "(?m_images @ System @@ 0V?$ map @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ HU?$ less @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@ 2 @ V?$ allocator @ U ?$ pair @ $$ CBV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H @ std @@@ 2 @@ std @@ A)
明るいチャップスの誰かが私を助けてくれますか?