|
Boost Users : |
From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2006-10-25 07:49:37
Wu Yinghui, Freddie wrote:
> Dear all,
>
> I'm implementing a hierarchy of classes to handle different types of
> objects. The characteristics of these objects are mostly similar (so I
> can put them into a container that knows only about the pure abstract
> base interface type), but some properties are specific to each object
> types.
>
> I plan to use Boost.Parameter for its capability of providing named
> parameter to these object types. However, I have one problem in this
> approach: Since Boost.Parameter requires that the function processing
> the ArgumentPack to be a template, I cannot make it virtual (a member
> function template cannot be virtual) in my pure abstract base
> interface. Furthermore, due to the lack of "virtual" member function,
> I cannot use
> the base class pointer to provide these named parameters to some
> subclasses.
Depends on what you actually want to do. Perhaps you could use something
like the template pattern (pseudo-code):
-----
struct Parameters
: boost::parameter::parameters< ... >
{};
struct Base
{
BOOST_PARAMETER_MEMFUN(void, Work, 1, 4, Parameters)
{
DoWork( p[arg1], p[arg2|0], p[arg3|1] ... );
}
private:
virtual void DoWork(actual, args, goes, here) = 0;
};
class Derived : public Base
{
virtual void DoWork(actual, args, goes, here)
{
... use args ...
}
};
class Derived2 : public Base
{
virtual void DoWork(actual, args, goes, here)
{
... use args ...
}
};
-----
I've used something similar myself, hope that gives an idea on how to solve
your problem.
// Johan
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net