2013-06-01 1 views
1

У меня странная проблема. Как я могу это решить.Undefined Refrence to 'rpg :: draw_grid (int, int)'

Ошибка в отчете компилятора говорится: "16 | неопределенная ссылка на` рпг :: 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; 
     } 
} 

ответ

1

В соответствии с сообщением об ошибке компилятора:

неопределенная ссылка на `рпг :: draw_grid (Int, Int)

Это означает, что компилятор не может найти определение члена draw_grid в rpg.

Вы должны сообщить компилятору, что draw_grid является членом класса rpg:

void rpg::draw_grid(int x, int y) 
{  //^^You missed this part 
+0

ах мы встретимся снова, спасибо дружище. – Rijnhardt

+0

@Rijnhardt Вы можете встретить другие проблемы, так как вы в настоящее время инициализируете переменные-члены внутри класса. Вы должны узнать, как инициализировать переменные-члены с помощью конструкторов. – taocp

+0

Еще раз спасибо. – Rijnhardt

Смежные вопросы