Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-11-02 13:40:50


"Johan Nilsson" <r.johan.nilsson_at_[hidden]> writes:

>> 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.

Excellent answer. Also, be sure to check out the latest version of
Boost.Parameter that is in CVS (and on the release branch). It's
considerably easier to use.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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