I don't get it. I've been staring at the code the code for a few hours and I don't know how I can fix it.
The class I'm creating, called Weapon.
This is how I defined the constructor:
<pre lang="c++">template <class T1> Weapon (T1& A);
This is how I implement the constructor:
template<class T1> Weapon::Weapon(T1 & A)
{
if(A == Chicken)
{
(*texture).loadFromFile("Images/Egg.png");
sprite.setTexture(*texture);
sprite.setPosition((*(chickens.begin())).getPosition().x, (*(chickens.begin())).getPosition().y);
}
else if (A == Ship)
{
(*texture).loadFromFile("Images/Weapon.png");
sprite.setTexture(*texture);
sprit<code></code>e.setPosition(ship.getPosition());
}
}
And I have error:
C2512 "Weapon": no appriopriate default constructor available
When I click on it, another one shows up:
E0291 no default constructor exists for class "Weapon"
and redirects me to the file "Engine.cpp"
Engine::Engine(RenderWindow & window)
{
if (!background.loadFromFile("data/images/background.png"))
{
MessageBox(NULL, "Textures not found!", "ERROR", NULL);
return;
}
runEngine(window);
}
and points to the opening brace.
My class Engine looks like this:
class Engine
{
public:
Engine(RenderWindow &win);
~Engine(void);
void runEngine(RenderWindow &window);
template <class T1, class T2> bool isIntersecting(T1& A, T2& B);
template <class T1, class T2> bool collisionTest(T1& A, T2& B);
private:
Ship ship;
Weapon weapon;
Weapon egg;
vector<Chicken> chickens;
Texture background;
};
Thanks in advance.
What I have tried:
change the declaration of the constructor, in Weapon and in Engine