I am working on drawing shapes using strings with C++. So I wrote a class of Shapes that serves as a base class to 2 derived classes, which are Diamond and Square. My virtual void function setStars() basically stores the coordinates of the points of the shape that I am going to print on a board of strings. Nevertheless, the function is involved with a LNK 2019 problem which I have no idea why. This is my code for the base class.
#ifndef _SHAPE_
#define _SHAPE_
#include <utility>
#include <vector>
class Shape {
protected:
int x, y, sz;//x-coordinate, y-coordinate, size of Shape
public:
std::vector<std::pair<int, int>> listOfPoints;
Shape(int xPos, int yPos, int size) : x(xPos), y(yPos), sz(size) { setStars(); }
virtual void setStars() = 0;
void moveBy(int xMove, int yMove) {
x += xMove;
y += yMove;
setStars();
}
void setSize(int size) {
sz = size;
setStars();
}
virtual ~Shape() = default;
};
#endif
The setStars() function is defined in the other derived classes. But I get this error:
unresolved external symbol "public: virtual void __thiscall Shape::setStars(void)" (?setStars@Shape@@UAEXXZ) referenced in function "public: __thiscall Shape::Shape(int,int,int)" (??0Shape@@QAE@HHH@Z)
Can someone explain to me what is wrong?