ページ 11

あるコードのエラーの解決方法が・・・

Posted: 2010年12月21日(火) 23:37
by Suikaba
分からないことがあります。
以下のコードで次のようなエラーが出ます。

コード:

// GameObject.h

#pragma once

#include <string>   
using namespace std;   
  
#include <hash_map>   
using namespace stdext;  


#include <tchar.h>
#include <windows.h>

#include <list>
using namespace std;

#include <dxerr9.h>
#include <d3d9.h>
#include <d3dx9.h>

#if _DEBUG
#include <crtdbg.h>
#define new  new( _NORMAL_BLOCK, __FILE__, __LINE__ )
#endif

#define RELEASE(x) {if(x) x->Release();}
inline float d2r(float d)
{
	return (d / 180.0f * D3DX_PI);
}

class CGameObject;

#define NAME_SIZE 32
struct ListData
{
	int priority;			// 実行順位
	char name[NAME_SIZE];	// 管理名称
	CGameObject* gameobj;	// オブジェクトのポインタ
	bool autodelete;		// リスト削除と同時にオブジェクトも削除
};

class CGameObject
{
private:
	static HWND hWnd;
	static HINSTANCE hInstance;

	friend int APIENTRY _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int);

	BOOL Initialize(HWND hWnd, HINSTANCE hInstance);
	void Uninitialize();
	void DoAllTasks();

	// リストの宣言
	static list<ListData> objectlist;

	// タスク処理時における仮イテレータ
	static bool it_moved;
	static list<ListData>::iterator it_task;

	// アイテムボックスの宣言
	static hash_map<string, CGameObject*> itembox;

public:
	// オブジェクトを格納
	static void AppendItemBox(LPCSTR name, CGameObject* object);
	// 指定したキーに格納されているオブジェクトを取り除く
	// (実際に削除するときはRemoveObjectを使うこと!!)
	static void RemoveItemBox(LPCSTR name);
	// アイテムボックス内のデータをすべて取り除く
	static void ResetItemBox();
	// 指定した文字列に対するオブジェクトを取得する
	static CGameObject* FindItemBox(LPCSTR name);

	virtual ~CGameObject(){}

	static const HWND GetHWnd(){ return hWnd; }
	static const HINSTANCE GetHInstance(){ return hInstance; }

	static void AppendObject(ListData &listdata);
	static void AppendObject(CGameObject *object, int priority, bool autodelete);
	static void AppendObject(CGameObject *object,
		int priority, LPCSTR name, bool autodelete);

	static void RemoveObject(CGameObject *target);
	static void RemoveObject(int p_begin, int p_end);

	CGameObject* FindObject(char* name);

protected:
	static LPDIRECT3D9 pD3D;
	static LPDIRECT3DDEVICE9 pD3Ddevice;
	static LPD3DXSPRITE pSprite;

	virtual void Init(){}
	virtual void Exec(){}
};

コード:

// ItemBox.cpp

#include "GameObject.h"

void CGameObject::AppendItemBox(LPCSTR name, CGameObject *object)
{
	itembox.insert(make_pair(name, object));
}

void CGameObject::RemoveItemBox(LPCSTR name)
{
	itembox.erase(name);
}

void CGameObject::ResetItemBox()
{
	itembox.clear();
}

CGameObject* CGameObject::FindItemBox(LPCSTR name)
{
	hash_map<string, CGameObject*>::iterator i;
	i = itembox.find(name);

	if(i == itembox.end()) return NULL;

	return i->second;
}
ItemBox.obj : error LNK2001: 外部シンボル ""private: static class stdext::hash_map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class CGameObject *,class stdext::hash_compare<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class CGameObject *> > > CGameObject::itembox" (?itembox@CGameObject@@0V?$hash_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVCGameObject@@V?$hash_compare@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@stdext@@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVCGameObject@@@std@@@2@@stdext@@A)" は未解決です。

というエラーなのですが・・・
とても長くてすいません。ほかにもありますが、問題があるとすればここだとおもいます。
しらべてみても、何が悪いかよく分からないです・・・

Re: あるコードのエラーの解決方法が・・・

Posted: 2010年12月21日(火) 23:40
by Suiaba
すいません
まちがって2回もしてしまいました
申し訳ございません。

Re: あるコードのエラーの解決方法が・・・

Posted: 2010年12月22日(水) 00:28
by ぬっち
staticで宣言した変数を定義していますか?
このコードを見た限りではしていませんよね?

参考URL : http://hpcgi1.nifty.com/MADIA/Vcbbs/www ... 020024.txt

Re: あるコードのエラーの解決方法が・・・

Posted: 2010年12月22日(水) 12:23
by Suikaba
>>ぬっちさん

それは分かってたんですが、どういう風に定義すればいいと思いますか?
それくらい調べろよ、とかいわれてしまうとそのとおりなのですが、できれば詳しくお願いします。

Re: あるコードのエラーの解決方法が・・・

Posted: 2010年12月22日(水) 12:53
by Suikaba
解決しました!!
いろいろ自分でいじってみたらできました。
これもぬっちさんのおかげです。ありがとうございました。