visual stadio 未解決の外部シンボルのエラーの解決法

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
kino

visual stadio 未解決の外部シンボルのエラーの解決法

#1

投稿記事 by kino » 11年前

プログラミングの館のまとめとしてポインタで引数として戻り値を得る確認プログラムを作りました。
あと少しなのですが、どうしても player_getcontrolKey()関数のビルドエラーがなくなりません。

開発環境はvisual stadio 2010です。
エラーは"1>main.obj : error LNK2019: 未解決の外部シンボル "public: void __thiscall Player::player_getcontrolKey(int *,int *)" (?player_getcontrolKey@Player@@QAEXPAH0@Z) が関数 _WinMain@16 で参照されました。"です。

これをなおすためにはポインタで処理するのをやめたほうがよいのでしょうか? それともほかのエラーなのでしょうか?

コード:

 
/*main.cpp*/
#include"DxLib.h"
#include"player.h"
#include"enemy.h"
#include"keyboard.h"

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
        ChangeWindowMode(TRUE),DxLib_Init(),SetDrawScreen( DX_SCREEN_BACK );
		//playerクラスの初期化
		Player WAI;
        while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 ){
			{	
				//キー入力状態更新
				Keyboard_Update();
				//キーボード入力取得
				Keyboard_Get();
				
				 //引数をポインタにして戻り値を得る
				WAI.player_getcontrolKey(&WAI.x,&WAI.y);
				//描画フェーズ
				WAI.player_ShowPlayer(WAI.x,WAI.y);
				}
			}
        DxLib_End();
        return 0;
}

コード:

 
/*Player.h*/
#ifndef DEF_PLAYER_H
#define DEF_PLAYER_H

class Player {
	public:
		int x ;
		int y ;
		int Image;

		//コンストラクタ クラスの初期化
		Player();

	//計算フェーズ
		//player移動
		void player_getcontrolKey(int *x,int *y);
		
	//描画フェーズ
		//playerを描画
		void player_ShowPlayer(int x,int y);
};
#endif
 

コード:

  
/*player.cpp*/
#include"DxLib.h"
#include"player.h"
#include"keyboard.h"
//コンストラクタ
Player::Player()
{
	x = 100;
	y = 100;
	Image =  LoadGraph("主人公.png");
}
//player移動方向
void player_getcontrolKey(int* x,int* y)
{	
	if(KeyCode[ KEY_INPUT_RIGHT ] >1){
		*x--;
	}
	if(KeyCode[ KEY_INPUT_LEFT ]>1){
		*x++;
	}
	if(KeyCode[ KEY_INPUT_DOWN ]>1){
		*y++;
	}
	if(KeyCode[ KEY_INPUT_UP ]>1){
		*y++;
	}
}
//プレイヤーの描画
void Player::player_ShowPlayer(int x,int y)
{ 	
	//描画関数
	DrawGraph(x,y,Image,TRUE);

}

コード:

  
/*Keyboard.h*/
#ifndef DEF_Keyboard_H//二重宣言防止
#define DEF_Keyboard_H

	//グローバル変数で入力状態からキーコードを得る
	static char m_Key[256] ;  // キーの入力状態格納用変数
	//キーボード入力状態更新
	void Keyboard_Update();

	static char KeyCode[256];
	//キーボード入力の取得
	void Keyboard_Get();
#endif

コード:

 
/*Keyboard.cpp*/
#include"DxLib.h"
#include"keyboard.h"

// キーの入力状態更新
void Keyboard_Update(){
	
	//初期化
	for(int a=0;a<256;a++){m_Key[a] = 0;}

        char tmpKey[256];             // 現在のキーの入力状態を格納する
        GetHitKeyStateAll( tmpKey );  // 全てのキーの入力状態を得る
        for( int i=0; i<256; i++ ){ 
                if( tmpKey[i] != 0 ){ // i番のキーコードに対応するキーが押されていたら
                        m_Key[i] ;   // 加算
                } else {              // 押されていなければ
                        m_Key[i] = 0; // 0にする
                }
        }
}


// KeyCodeのキーの入力状態を取得する
void Keyboard_Get(){
	//初期化	
	for(int a=0;a<256;a++){
		KeyCode[a] = 0;
	}
	
	// KeyCodeの入力状態を返す
	for(int b=0;b<256;b++){
		KeyCode[b] = m_Key[b]; 
	}
} 


Poco
記事: 161
登録日時: 14年前

Re: visual stadio 未解決の外部シンボルのエラーの解決法

#2

投稿記事 by Poco » 11年前

player.cppで
×void player_getcontrolKey(int* x,int* y)
○void Player::player_getcontrolKey(int* x,int* y)

閉鎖

“C言語何でも質問掲示板” へ戻る