Reputation: 1
I am programming this game for a university work and i believe that my code is right, but i keep getting this error and it is keeping me from finishing my work in time. So here's the game board class header:
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstdio>
class CMagicAlchemistBoard
{
public:
CMagicAlchemistBoard(void); // Default Constructor
CMagicAlchemistBoard(const CMagicAlchemistBoard& board); // Copy Constructor
~CMagicAlchemistBoard(void ); // Destructor
void SetupBoard(void); // Function to setup the board
int GetBoardSpace(int row, int col); // Get the color at row,col
// Accessor functions to get/set board size information
int GetColumns(void) const { return m_nColumns; }
void SetColumns(int nColumns) { m_nColumns = (nColumns >= 6) ? nColumns : 6; }
int GetRows(void) const { return m_nRows; }
void SetRows(int nRows) { m_nRows = (nRows >= 8) ? nRows : 8; }
void DeleteBoard(void); // Function to delete the board and free memory
void ExecuteMove(int row, int col);
bool IsGameOver(void) const; // Is the game over?
void DrawBoard(void);
bool ValidMove(int row, int col); // Function to see if a move is valid
private:
void CreateBoard(void); //Function to create the board and allocate memory
// Class Data
int** m_arrBoard; // 2D array pointer
// Board size information
char m_arrChars[10];
int m_nColumns;
int m_nRows;
};
And here is the .cpp file with only the implementation of the DrawBoard() function:
#include "cmagicalchemistboard.h"
using namespace std;
void CMagicAlchemistBoard::DrawBoard(void)
{
cout << "MAGIC ALCHEMIST" << endl;
cout << " ";
for(int col = 0; col < m_nColumns; col++){ printf(" ---",col); }
cout << endl;
for(int row = 0; row < m_nRows; row++)
{
for(int col = 0; col < m_nColumns; col++)
{
cout << "| " << m_arrChars[GetBoardSpace(row, col)];
}
cout << "| " << endl;
}
}
I pretend to use this function on another class. Here's the header of that class:
#include "cmagicalchemistboard.h"
#include <iostream>
#include <cstdlib>
#include <conio.h> //Contains the function getch(), which reads the input from the keyboard
#define LEFT_ARROW 75
#define RIGHT_ARROW 77
#define UP_ARROW 72
#define DOWN_ARROW 80
#define ESC 27
class CMagicAlchemist
{
public:
CMagicAlchemist();
~CMagicAlchemist();
// Functions for accessing the game board
char GetBoardSpace(int row, int col) { return m_board->GetBoardSpace(row, col); }
void SetupBoard(void) { m_board->SetupBoard(); }
int GetColumns(void) { return m_board->GetColumns(); }
void SetColumns(int nColumns) { m_board->SetColumns(nColumns); }
int GetRows(void) { return m_board->GetRows(); }
void SetRows(int nRows) { m_board->SetRows(nRows); }
void DeleteBoard(void) { m_board->DeleteBoard(); }
bool IsGameOver() { return m_board->IsGameOver(); }
void InputGameParameters();
void GetMove(int &row, int &col);
void DrawBoard();
void NewGame();
void Game();
private:
CMagicAlchemistBoard* m_board; // Instance of the game board
int m_nmoves;
};
And finally, the .cpp file of this last class with only the implementation of the function that calls the DrawBoard() function:
#include "cmagicalchemist.h"
void CMagicAlchemist::Game()
{
int x,y;
InputGameParameters();
NewGame();
DrawBoard();
}
So, my problem is: when i compile this program im getting this error: "undefined reference to CMagicAlchemist::DrawBoard()". This is stupid because the DrawBoard() function doesnt even belong to CMagicAlchemist class but instead, it belong to CMagicAlchemistBoard class. Can somebody help me?
Upvotes: 0
Views: 819
Reputation: 21627
You have DrawBoard declared in your CMagicAlchemist class. You call DrawBoard from a CMagicAlchemist member function.
That tries to call Drawboard for the CMagicAlchemist class.
Upvotes: 1