Hello.
I have a base class that has a variable that needs to be set when the class object is made.
But when i inherit the class, i have no idea how to invoke the constructor, what are workarounds?
How can constructor of MainMenu class also invoke Collision constructor?
//I have class like this, its used as a base class
//NOTE its constructor is taking a argument
class Collision
{
public:
Collision(sf::RenderWindow *RenWin);
bool Col_RectMouse(sf::RectangleShape &rec);
private:
sf::RenderWindow *renWin;
};
//The functions the above class uses
Collision::Collision(sf::RenderWindow *RenWin)
{
this->renWin = RenWin;
}
bool Collision::Col_RectMouse(sf::RectangleShape &rec)
{
int x = sf::Mouse::getPosition(*renWin).x;
int y = sf::Mouse::getPosition(*renWin).y;
if(x > rec.getPosition().x &&
x < rec.getPosition().x + rec.getSize().x &&
y > rec.getPosition().y &&
y < rec.getPosition().y + rec.getSize().y)
{
return true;//Collision
}
return false;//No collision
}
//Then a class that inherits the base class
class MainMenu : public Collision
{
public:
MainMenu();
void Draw(sf::RenderWindow &renWin);
private:
sf::RectangleShape Continue, NewGame, Options, Exit;
};
//Code of functions for above class
MainMenu::MainMenu()
{ //Error, no default constructor exists for class "Collision"
Continue.setFillColor(sf::Color(100,100,100));
Continue.setPosition(0, 0);
//...
}