"Оружие": нет подходящего конструктора по умолчанию availa
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);
Вот как я реализую конструктор:
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()); } }
И у меня есть ошибка:
C2512 "Weapon": no appriopriate default constructor available
Когда я нажимаю на него, появляется еще один:
E0291 no default constructor exists for class "Weapon"
и перенаправляет меня к файлу "Engine.cpp"
Engine::Engine(RenderWindow & window) { if (!background.loadFromFile("data/images/background.png")) { MessageBox(NULL, "Textures not found!", "ERROR", NULL); return; } runEngine(window); }
и указывает на открывающую скобу.
Мой движок класса выглядит так:
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; };
Заранее спасибо.
Что я уже пробовал:
change the declaration of the constructor, in Weapon and in Engine