So I have been working with a tutorial using Xcode, C++, and SFML (Link to Tutorial Website)
I built the code and it worked perfectly. Then, I went through and changed the names of a few of the classes (from lower case to upper case). I went through and built everything to make sure i had changed everything i needed to and i did. Then, when i built and ran the program, i got the follow two errors:
Field type 'GUI' is an abstract class
and
Allocating an object of abstract class type 'GUI'
I know that an abstract class contains a "virtual" function, which GUI does, but why would the error be caused if i havent touched the function at all? I guess I just dont really understand what is causing the error, nor do i know how to fix it.
Here is the code for the GUI class:
class GUI : public sf::Transformable, public sf::Drawable {
private:
/* If true the menu entries will be horizontally, not vertically, adjacent */
bool horizontal;
GUIStyle style;
sf::Vector2f dimensions;
int padding;
public:
std::vector<GUIEntry> entries;
bool visible;
/* Constructor */
GUI(sf::Vector2f dimensions, int padding, bool horizontal, GUIStyle& style, std::vector<std::pair<std::string, std::string>> entries) {
visible = false;
this->horizontal = horizontal;
this->style = style;
this->dimensions = dimensions;
this->padding = padding;
/* Construct the background shape */
sf::RectangleShape shape;
shape.setSize(dimensions);
shape.setFillColor(style.bodyCol);
shape.setOutlineThickness(-style.borderSize);
shape.setOutlineColor(style.borderCol);
/* Construct each gui entry */
for(auto entry : entries) {
/* Construct the text */
sf::Text text;
text.setString(entry.first);
text.setFont(*style.font);
text.setFillColor(style.textCol);
text.setCharacterSize(dimensions.y-style.borderSize-padding);
this->entries.push_back(GUIEntry(entry.second, shape, text));
}
}
sf::Vector2f GetSize();
/* Return the entry that the mouse is hovering over. Returns
* -1 if the mouse if outside of the Gui */
int GetEntry(const sf::Vector2f mousePos);
/* Change the text of an entry */
void SetEntryText(int entry, std::string text);
/* Change the entry dimensions */
void SetDimensions(sf::Vector2f dimensions);
/* Draw the menu */
virtual void Draw(sf::RenderTarget& target, sf::RenderStates states) const;
void Show();
void Hide();
/* Highlights an entry of the menu */
void Highlight(const int entry);
/* Return the message bound to the entry */
std::string Activate(const int entry);
std::string Activate(const sf::Vector2f mousePos);
};
And here is the line where the error is (the underlined GUI is where the error is):
this->guiSystem.emplace("rightClickMenu", GUI(sf::Vector2f(196, 16), 2, false, this->game->stylesheets.at("button"),
{
std::make_pair("Flatten $" + this->game->tileAtlas["grass"].GetCost(), "grass"),
std::make_pair("Forest $" + this->game->tileAtlas["forest"].GetCost(), "forest" ),
std::make_pair("Residential Zone $" + this->game->tileAtlas["residential"].GetCost(), "residential"),
std::make_pair("Commercial Zone $" + this->game->tileAtlas["commercial"].GetCost(), "commercial"),
std::make_pair("Industrial Zone $" + this->game->tileAtlas["industrial"].GetCost(), "industrial"),
std::make_pair("Road $" + this->game->tileAtlas["road"].GetCost(), "road")
}));
Anyways, the question I have is what is causing this error and how do I fix it?
Thank you!