I use a parent class which has some virtual methods. When I call the virtual method in the constructor, it gives LNK2019
and LNK1120
errors with "error LNK2019: unresolved external symbol "protected: virtual int ... referenced in function "public: __thiscall ...
" and "...\Debug\8puzzleProject.exe : fatal error LNK1120: 1 unresolved externals
" messages.
Is there way to solve this problem or shoudn't I call a virtual method in the constructor?
Thank you!
Here is the codes:
Class with errors:
#ifndef HEURISTICSEARCH_H
#define HEURISTICSEARCH_H
#include "BruteSearch.h"
class HeuristicSearch: public BruteSearch
{
public:
HeuristicSearch( int initial[BOARD_LIMIT][BOARD_LIMIT] );
bool search();
protected:
virtual int calculateUtility() = 0;
virtual int calculateUtility( Node* ) = 0;
bool check4Goal();
void checkNmove();
int findMin(int* values );
int utilityCost;
};
#endif
HeuristicSearch::HeuristicSearch( int initial[BOARD_LIMIT][BOARD_LIMIT] )
:BruteSearch( initial )
{
utilityCost = calculateUtility(); //After deleting this line, the error's gone
}
Parent class of the parent class (There is no error)
#ifndef BRUTESEARCH_H
#define BRUTESEARCH_H
#include <iostream>
#include <queue>
#include "Constants.h"
#include "Node.h"
class BruteSearch
{
public:
BruteSearch( int initial[BOARD_LIMIT][BOARD_LIMIT] );
virtual bool search(){ return false; }
protected:
bool check4Goal();
void printBoard();
int turn;
int goalBoard[BOARD_LIMIT][BOARD_LIMIT] ;
Node *currentPtr;
};
#endif