Reputation: 1857
I am very desperate my other classes which have the same inheritance works, this class that I have written was just so simple, it no longer works. I don't know what to do, this is very very frustrating, in fact it is simple class that defines the enemy which do simple predetermined behavior upon their creation.
#include "RD_Infested.hpp"
#include "World.hpp"
#include "SteeringBehavior.hpp"
RD_Infested::RD_Infested(const string& oname, const sf::Vector2f& position, esc::World & w )
: esc::Critter(oname , position, w),
esc::Offensive(*this)
{
esc::Critter::setPathTraversalPolicy(new esc::SteeringBehavior(*this));
}
RD_Infested::~RD_Infested()
{
}
void RD_Infested::update( float e )
{
if (!esc::Object::isActive() )
return;
esc::Offensive::executeAttackOrder( e );
esc::Offensive::executeDefensiveStance( e );
if ( !esc::Offensive::isOnAttackRange() )
esc::Critter::makePursuit( e );
esc::Critter::getPathTraversalPolicy()->updatePolicy( e );
}
RD_Infested* RD_Infested::getInstance()
{
return this;
}
Here its class header:
#ifndef RD_INFESTED_HPP
#define RD_INFESTED_HPP
#include <SFML/Graphics.hpp>
#include "Critter.hpp"
#include "Offensive.hpp"
class RD_Infested : public esc::Critter,
public virtual esc::Offensive
{
public:
RD_Infested( const string&, const sf::Vector2f&, esc::World& );
virtual ~RD_Infested();
virtual void update( float = 0.0f );
RD_Infested* getInstance();
};
#endif // RD_INFESTED_HPP
So what this class does is to inherit from Critter which is a moving object and Offensive being its behavior so in turn conceptually it becomes 'an Offensive Critter'.
This is the error it gives me:
error: no matching function for call to 'esc::Behavior::Behavior()'|
Here is Offensive class: I have removed the unnecessary functions
#ifndef OFFENSIVE_HPP
#define OFFENSIVE_HPP
#include <string>
using std::string;
#include<stack>
using std::stack;
#include "Behavior.hpp"
#include "Weapon.hpp"
namespace esc
{
class World;
class Object;
class Critter;
class Manager;
class AttackCapability;
// Worlds
class Offensive : public virtual Behavior
{
public:
/****/
protected:
explicit Offensive( Critter * );
virtual ~Offensive();
private:
/****/
};
}
#endif // OFFENSIVE_HPP
And here is Behavior class:
#ifndef BEHAVIOR_HPP
#define BEHAVIOR_HPP
#include<stack>
using std::stack;
#include <string>
using std::string;
#include "Critter.hpp"
namespace esc
{
class World;
class Behavior
{
protected:
explicit Behavior( Critter * );
virtual ~Behavior();
/****/
private:
/****/
};
}
#endif // BEHAVIOR_HPP
This one error I do not know how to fix. I did my research about having default ctor being generated but I still don't know or even understand this kind of problem. I don't know how to fix this one.
Thanks. :)
Upvotes: 1
Views: 630
Reputation: 5118
error: no matching function for call to 'esc::Behavior::Behavior()'|
Some part of your client probably code tries to create a TestConstructDerived
instance using its default constructor.
This default constructor is defined (since it's not disabled by the definition of a constructor with arguments or by = delete
), but the default constructor for Offensive
isn't, since it has a constructor with arguments defined.
See this question for details about the conditions under which default constructors are defined.
Upvotes: 1
Reputation: 319
Your Offensive
constructor expects a pointer to a Critter
object:
explicit Offensive( Critter * );
but you pass an object to it
esc::Offensive( *this )
as this
is a pointer and you dereference it. So just use esc::Offensive(this)
. But the next point is that this might not be a good idea to pass a this
pointer to a base class constructor in the constructors initializer list of the derived class.
Upvotes: 2