ページ 11

error LNK2001 が解決できません

Posted: 2015年3月31日(火) 21:27
by 松matu
シューティングゲームを作っていて、プレー中に「p」キーを押すと、メニューリストが表示されるように
したいのですが、以下のようなエラーが出て、うまくいきません。何が原因かわかる方がいらしたら、教えてください


1>PlayScene.obj : error LNK2001: 外部シンボル ""class MenuList * menulist" (?menulist@@3PAVMenuList@@A)" は未解決です。
1>C:\Users\masakimatuura\Downloads\passer\Debug\GameProg.exe : fatal error LNK1120: 外部参照 1 が未解決です。



globals.h

コード:


#pragma once

const int p_Speed = 2;
const int hn_speed = 17;
const int shot_max = 100;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int MAP_HEIGHT = 30;
const int MAP_WIDTH = 120;
const int MapChip_Size = 32;
const int CHAR_SIZE = 32;
const int MAP_NUM = 1;

#include "GameScene.h"	
#include "PlayScene.h"
#include "TitleScene.h"
#include "GameOverScene.h"
#include "StageManeger.h"
#include "Stage1.h"
#include "Stage2.h"
#include "Stage3.h"
#include "MenuManager.h"
#include "MenuList.h"

extern GameScene *currentScene;
extern PlayScene *playScene;
extern TitleScene *titleScene;
extern GameOverScene *gameoverScene;
extern StageManeger *currentStage;
extern Stage1 *st1;
extern Stage2 *st2;
extern Stage3 *st3;
extern MenuManager *currentmenu;
extern MenuList *menulist;

MenuManager.h

コード:


#pragma once

class MenuManager
{
public:
	virtual void list_draw() = 0;
	virtual void list_update() = 0;
};

MenuList.h

コード:


#pragma once

#include "MenuManager.h"

class MenuList : public MenuManager
{
	int m_graph;

public:
	MenuList();

	void list_draw();
	void list_update();
};


MenuList.cpp

コード:



#include "DxLib.h"
#include "Globals.h"
//#include "MenuList.h"

MenuList::MenuList()
{
	m_graph = LoadGraph("passer画像/hana2.png");
}

void MenuList::list_draw()
{
	DrawGraph(0, 0, m_graph, TRUE);
	DrawFormatString(2, 5, GetColor(255, 255, 255), "アイテム");
	DrawFormatString(2, 15, GetColor(255, 255, 255), "セーブ");
	DrawFormatString(2, 30, GetColor(255, 255, 255), "ゲーム終了");
	DrawFormatString(2, 45, GetColor(255, 255, 255), "装備");
	DrawFormatString(2, 45, GetColor(255, 255, 255), "地図");
	DrawFormatString(2, 45, GetColor(255, 255, 255), "ミッション一覧");
}

void MenuList::list_update()
{
	if(CheckHitKey(KEY_INPUT_P)){
		list_draw();
	}
}
PlayScene.h

コード:


#include "Globals.h"

PlayScene::PlayScene() //PlaySceneで呼び出されている、PlayScene関数の処理定義
{
	player = new Player(Point2D(300, 480)); //playerの初期化
	enemy = new Enemy(Point2D(0, 0));
	mouseCursor = new MouseCursor();

	//ステージ初期化
	st1 = new Stage1(*player);
	st2 = new Stage2(*player);
	st3 = new Stage3(*player);
	currentStage = st1;

	//メニュー画面初期化
	menulist = new MenuList();
	//currentmenu = menulist;
}

PlayScene::~PlayScene()
{
	delete player;
	delete enemy;
	delete mouseCursor;
	delete st1;
	delete st2;
	delete st3;
	delete menulist;
}

void PlayScene::draw() //PlaySceneで呼び出されているdraw関数の処理定義
{
	currentStage->draw(*player); //ステージ画像描画

	player->draw(*st1); //player画像描画
	enemy->draw(); //敵画像描画

	player->rePoint();
	enemy->rePoint();
}

void PlayScene::update(MouseCursor *mouseCursor)
{	
	currentStage->next_stage(*player); //現在のnext_stage関数を呼び出す
	currentStage->isHitMap(*player);

	mouseCursor->move(); //銃カーソルの描画

	player->move(mouseCursor, *player); //プレイヤーの移動
	player->shot(mouseCursor); //プレイヤーの弾発射
	player->isInsector(*enemy); //プレイヤーの敵との当たり判定

	enemy->move(); //敵の移動
	enemy->isInsector(*player); //敵のプレイやーとの当たり判定
		
	//currentmenu->list_update();

	if(CheckHitKey(KEY_INPUT_Q)){
		currentScene = gameoverScene;
	}
}




Re: error LNK2001 が解決できません

Posted: 2015年3月31日(火) 21:48
by みけCAT
エラーメッセージの通りmenulistの実体が無いのだろうと思いますが、提示されたコードの中にcurrentSceneなどの実体も無いようなのでわかりません。
スペルミスが無いか確認してください。

Re: error LNK2001 が解決できません

Posted: 2015年3月31日(火) 21:57
by 松matu
すぺるも確認しましたが、ミスはありませんでした。

StageManager.h(currentScene)

コード:

#pragma once

#include "MapHitCollision.h"

struct Player;

class StageManeger
{
protected:
	int DrawBase_x, DrawBase_y;

public:
	MapHitCollision *mp;

	StageManeger();
	~StageManeger();

	virtual void draw(const Player& Pl) = 0;
	virtual void isHitMap(const Player& Pl) = 0;
	virtual void next_stage(const Player& Pl) = 0;
};

Re: error LNK2001 が解決できません

Posted: 2015年3月31日(火) 22:11
by box
松matu さんが書きました:

コード:

extern MenuList *menulist;
このように書いてあるということは、Menulist型へのポインター変数であるmenulistの
実体をどこか別のところで定義してあって、私はそれを使いますよ、と言っているわけですね。

ところが、くだんのリンクエラーの内容によると、menulistの実体定義が見当たらない、
と言っているわけです。
なので、「スペルミスはありませんか?」という回答が来ているのです。

今一度確認なさってはいかがでしょうか。

Re: error LNK2001 が解決できません

Posted: 2015年3月31日(火) 22:20
by みけCAT
オフトピック
今回は本題とはあまり関係無さそうですが、includeの関係を一旦整理してみました。

コード:

日- MenuList.cpp
├田- DxLib.h
└日- globals.h
 ├田- GameScene.h
 ├日- PlayScene.h
 │└- Globals.h <dupe>
 ├田- TitleScene.h
 ├田- GameOverScene.h
 ├日- StageManager.h
 │└田- MapHitCollision.h
 ├田- Stage1.h
 ├田- Stage2.h
 ├田- Stage3.h
 ├日- MenuManager.h
 │└- (なし)
 └日- MenuList.h
  └- MenuManager.h <dupe>
古いWindowsのツリービューをイメージし、田が付いているファイル名はincludeされているが未公開のものです。
この投稿は、未公開のソースコードの公開を求めるものではありません。

globals.hからincludeされているPlayScene.hでまたGlobals.hがincludeされているのが若干気になりましたが、
今回は特に問題ではなさそうです。