class robot_generic
{
  public :
		template<typename Request, typename Response>
		bool const queryDriver(Request const &req, Response &res)
		{
			//some jobs, blah blah blah 
		}

		template<typename Request, typename Response>
		bool const queryMoney(Request const &req, Response &res)
		{
			//some jobs, blah blah blah 
		}
};

class robot_A : public robot_generic
{
	public :
		template<typename Request, typename Response>
		bool const queryFood(Request const &req, Response &res)
		{
			//some jobs, blah blah blah 
		}
};

class robot_B : public robot_generic
{
  public :
		template<typename Request, typename Response>
		bool const queryFood(Request const &req, Response &res)
		{
			//some jobs, blah blah blah 
		}

		template<typename Request, typename Response>
		bool const queryWater(Request const &req, Response &res)
		{
			//some jobs, blah blah blah 
		}
};

class robot_C : public robot_generic
{
	public :
		template<typename Request, typename Response>
		bool const queryWater(Request const &req, Response &res)
		{
			//some jobs, blah blah blah 
		}

		template<typename Request, typename Response>
		bool const queryMovie(Request const &req, Response &res)
		{
			//some jobs, blah blah blah 
		}
};

As you can see, every member functions of query are the same
yet I have to reimplement those same member functions in different classes
Although I would like to use policy based design to solve this kind of
composition problem, but it would induce heavy multiple inheritance.

The codes are like this

struct query_food
{
  template<typename Request, typename Response>
  bool const queryFood(Request const &req, Response &res)
	{
			//some jobs, blah blah blah 
	}
};

struct query_movie
{
  template<typename Request, typename Response>
  bool const queryMovie(Request const &req, Response &res)
	{
			//some jobs, blah blah blah 
	}
};

struct query_water
{
  template<typename Request, typename Response>
  bool const queryWater(Request const &req, Response &res)
	{
			//some jobs, blah blah blah 
	}
};

template<typename QueryPolicy>
class robot_generic : public QueryPolicy
{
  public :
		template<typename Request, typename Response>
		bool const queryDriver(Request const &req, Response &res)
		{
			//some jobs, blah blah blah 
		}

		template<typename Request, typename Response>
		bool const queryMoney(Request const &req, Response &res)
		{
			//some jobs, blah blah blah 
		}
};

template<typename QP_one, typename QP_two>
struct binaryQuery : public QP_one, public QP_two
{
};

typedef binaryQuery<query_food, query_water> query_food_water;
typedef binaryQuery<query_water, query_movie> query_water_movie;

typedef robot_generic<query_food> robotA;
typedef robot_generic<query_food_water> robotB;
typedef robot_generic<query_water_movie> robotC;

Exactly, what is the benefits of policy based design over raw multiple inheritance?
Except of type safe, compiler manage the codes for us, don't need to type so many
words, do we still have another advantage?
I seldom use multiple inheritance, I only use it when I need to deal with the
situation like this

struct airplace_special : private engine, public airplane
{};

private means "is implemented in terms of" and public means "is a"

Do you have a better idea to solve this problem?
I need template member function
Although team member said we could use inheritance to simulate template
but using template is much more natural(don't need to use dynamic_cast), faster
and safer. Yet my team members...well, looks like they don't like template
They would rather write something like this rather than using template or
function overload.

if(typeid(TypeA) == typeid(TypeB)).....//blah blah blah

Or using boost::any associated with typeid and dynamic_cast even the type could
be deduce at compile time easily. I don't know what makes them so fascinated
to the world of dynamic binding.I don't dynamic binding is equal to OOP, it is only
a mechanism to implement OOP.

Besides, if we would like to deal with single paradigm--OOP, I don't think C++ is
a good choice, it lacks many things if you don't try to combine the power of
different paradigms.

ps : I forgot to declare the destructor under protected scope of those policy

The other solution is
wrap those small policy into one policies
when I need to do the selection, I could just declare those useless policy as
private member function

class robotD: public robotC
{
  private :
	  template<typename Request, typename Response>
    bool const queryWater(Request const &req, Response &res)
	  {		  
	  }
};

ok, I don't need to use heavy multiple inheritance just for one policies
But I like the "heavy inheritance" way rather than this one

bool const queryFood(Request const &request, Response &response, Func func);

I think functor is a better choice than multiple inheritance
But have to pass more parameters into the function

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.