I have some design problems, I thought one of you might have some clue to help me.
I tried to summarize my problem to this simple example :
I have two different class DerivedOne
and DerivedTwo
which inherit from the same Base
class and share the definition of a method.
I have a set of shared_ptr
pointing to client
, which have one object from two different class DerivedOne
and DerivedTwo
.
Because I don't want to use a Base*
pointer to hold this 2 different class, I tried to make the client class template.
But I have 2 different class, and I can't hold them in the same set.
I thought shared_ptr
could hold an object pointer without specifying the template argument, but I was wrong, or I don't know how to do.
The other solution I see, is to separate those 2 different client
in 2 different set
Thanks in advance for any suggestions.
Here is the code :
#include <iostream>
#include <set>
#include <boost/shared_ptr.hpp>
class Base
{
public:
virtual void test() = 0;
};
class Derived_one
: public Base
{
public:
void test() {
std::cout << "Derived One" << std::endl;
}
};
class Derived_two
: public Base
{
public:
void test() {
std::cout << "Derived Two" << std::endl;
}
};
template <class temp_arg>
class Client
{
public:
int test(){
obj_.test();
}
protected:
temp_arg obj_;
};
typedef Client<Derived_one> ClientOne;
typedef Client<Derived_two> ClientTwo;
/// Here I don't want to specify any of the two previously declared client :
//typedef boost::shared_ptr<Client> Client_ptr;
typedef boost::shared_ptr<ClientOne> Client_ptr;
int main(int, const char**)
{
std::set<Client_ptr> Clients_;
Client_ptr client_(new ClientOne());
Clients_.insert(client_);
client_->test();
return 0;
}
If you want to give a look to the real code :
https://github.com/gravitezero/Node/tree/experimental/src
Client
correspond to connection
The Base
class is message
The two derived class are peply
and request
.