c++:error LNK2019: unresolved external symbol של d'tor - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

c++:error LNK2019: unresolved external symbol של d'tor


AvIAToR

Recommended Posts

היי,

דרושה עזרתכם בפענוח השגיאה הנ"ל. הקוד:

RobotDB.h


[LEFT]#ifndef ROBOTDB_H
#define ROBOTDB_H

# include <vector>
# include "Robot.h"
# include "Map.h"

// A vector of robots
typedef std::vector<Robot*> RobotVec;
typedef std::vector<Robot*>::iterator RobotVec_it;
typedef std::vector<Robot*>::const_iterator RobotVec_cit;

class RobotDB
{
private:
RobotVec robots;
Map *map;

public:
RobotDB(){};
RobotDB(Map *new_map) : map(new_map){};
~RobotDB(void);
void DeleteRobot(const std::string& rName);
void PlaceRobot(std::string name, int x, int y);
void MoveRobot(std::string name, std::string direction);
std::vector<Robot*>::size_type findRobot(std::string name);
};


#endif
[/LEFT]

RobotDB.cpp


[LEFT]#include "RobotDB.h"

RobotDB::~RobotDB(void){
for (std::vector<Robot*>::size_type it = 0; it < robots.size(); ++it){
delete[] robots[it];
}
}

void RobotDB::PlaceRobot(std::string name, int x, int y){

Robot* pRobot = new Robot(Coordinate(x, y), name);
robots.push_back(pRobot);
}

void RobotDB::DeleteRobot(const std::string& rName){
std::vector<Robot*>::size_type sizeRobot = findRobot(rName);
delete[] robots[sizeRobot];
//robots.erase(robots.begin + sizeRobot);
}

void RobotDB::MoveRobot(std::string name, std::string direction){
std::vector<Robot*>::size_type citRobot = findRobot(name);
Coordinate c = robots[citRobot]->getCoord();

if(direction == "U"){
if(c.gety() == 0) robots[citRobot]->getOut(); // Robot gets out of bounds
else if( map->checkCell(c.getx(), c.gety()-1) == 0 ) // check if destination is path
robots[citRobot]->Move("U"); // command robot to move up
}
else if(direction == "D"){
if(c.gety() == map->getH()-1) robots[citRobot]->getOut(); // Robot gets out of bounds
else if( map->checkCell(c.getx(), c.gety()+1) == 0 ) // check if destination is path
robots[citRobot]->Move("D"); // command robot to move down
}
else if(direction == "L"){
if(c.getx() == 0) robots[citRobot]->getOut(); // Robot gets out of bounds
else if( map->checkCell(c.getx()-1, c.gety()) == 0 )
robots[citRobot]->Move("L"); // command robot to move left
}
else if(direction == "R"){
if(c.getx() == map->getW()-1) robots[citRobot]->getOut(); // Robot gets out of bounds
else if(map->checkCell(c.getx()+1, c.gety()) == 0)
robots[citRobot]->Move("R"); // command robot to move right
}
}

std::vector<Robot*>::size_type RobotDB::findRobot(std::string name){
for (std::vector<Robot*>::size_type it = 0; it < robots.size(); ++it){
if(robots[it]->getName() == name){
return it;
}
}
return 0;
}
[/LEFT]

השגיאה:


[LEFT]1>RobotDB.obj : error LNK2019: unresolved external symbol "public: __thiscall Robot::~Robot(void)" (??1Robot@@QAE@XZ) referenced in function "public: void * __thiscall Robot::`vector deleting destructor'(unsigned int)" (??_ERobot@@QAEPAXI@Z)
1>C:\Users\H\Desktop\jbr\3\jbr\Debug\jbr.exe : fatal error LNK1120: 1 unresolved externals[/LEFT]

חיפשתי הרבה בגוגל ולצערי לא מצאתי תשובה למה זה קורה..

אני לא מבין, הרי הוא אומר שלא מוצא d'tor אבל בפירוש ממומש לו אחד, שגם מוגדר ב header :nixweiss:

help :please:

תודה

קישור לתוכן
שתף באתרים אחרים

קודם כל תודה על התגובות :xyxthumbs:

קראתי את השורה הזאת מאה פעם ולא שמתי לב שרשום ~Robot ולא ~RobotDB

ואכן הוספת {} לחתימה של ה- d'tor של Robot ב- header שלו פתרה את הבעיה.

שוב תודה והמשך שבוע מצויין.

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...