1
이상한 문제가 있습니다. 어떻게 해결해야합니까? 컴파일러 보고서에Undefined Refrence to 'rpg :: draw_grid (int, int)'
오류가 상태 : | 당신이 도움이 될 수 있는지 궁금
"16 'RPG :: draw_grid (INT, INT)'에 대한 정의되지 않은 참조". 컴파일러 오류 메시지에 따르면
감사
MAIN.CPP
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "rpg.h"
using namespace std;
int main()
{
rpg class_rpg;
int x = 4; //Co-ordinates
int y = 4; //Co-ordinates
char choice;
class_rpg.draw_grid(x, y) ;
while (x > -1 && x < 10 && y > -1 && y && 10){
cout << "What direction shall you move?";
cin >> choice;
switch (choice){
case 'u':
x = x - 1;
y = y;
system("cls");
class_rpg.draw_grid(x,y);
}
}
cin.get();
return 0;
}
rpg.h
#include <iostream>
#include <cstdlib>
#include <ctime>
#ifndef RPG_H
#define RPG_H
class rpg
{
public:
rpg();
virtual ~rpg();
void generate_world();
void draw_grid(int x, int y);
char grid[9][9] = {{'.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.'}};
char character = '*';
char quest = 'Q';
int position[2];
int quest_position[2];
int quest_coord[2];
char direction;
int x,y;
protected:
private:
};
#endif // RPG_H
rpg.cpp
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "rpg.h"
using namespace std;
rpg::rpg()
{
//ctor
}
rpg::~rpg()
{
//dtor
}
void draw_grid(int x, int y)
{
rpg class_rpg;
int position[2] = {x,y};
int quest_position[2];
quest_position[0] = rand() % 9 + 0;
quest_position[1] = rand() % 9 + 0;
int quest_coord[2];
quest_coord[0] = quest_position[0];
quest_coord[1] = quest_position[1];
for(int i = 0; i < 9; i++){
for (int j = 0; j < 9; j++){
if(i == position[0] && j == position[1])
cout << class_rpg.character;
else if(i == quest_coord[0] && j == quest_coord[1])
cout << class_rpg.quest;
else
cout << class_rpg.grid[i][j];
cout << " ";
}
cout << endl;
}
}
아, 감사합니다 친구 :
당신은
draw_grid
클래스rpg
의 구성원 인 컴파일러를 말해야한다. – Rijnhardt@Rijnhardt 현재 클래스 내부의 멤버 변수를 초기화 했으므로 다른 문제가 발생할 수 있습니다. 생성자를 사용하여 멤버 변수를 초기화하는 방법을 찾아야합니다. – taocp
다시 감사드립니다. – Rijnhardt