עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

פורסם

היי,

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

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:

תודה

פורסם

מה הדיסטרקטור שלך עושה? אילו משאבים הקצאת (עם new) שאתה צריך לפנות בו?

פורסם

הוא לא מוצא את ה-dtor של Robot, לא של RobotDB.

איפה המימוש של Robot? יכול להיות שלא לינקג'ת אליו?

נערך על-ידי שניצל

פורסם
  • מחבר

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

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

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

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

ארכיון

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

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.