Boost logo

Boost Users :

From: Russell L. Carter (rcarter_at_[hidden])
Date: 2008-01-23 08:01:46


Hi,
This is probably a novice template question. I am curious what
I am doing wrong here, where I'm trying to get a function object
holding a base member of a CRTP class. gcc 4.2.3 complains about:

  type/value mismatch at argument 1 in template parameter list for
'template<class Derived> template<template<template<class> class MHBase>
template<class Derived> template<class> class MHBase> struct MHBase<
<template-parameter-1-1> >::fooFO

Any help appreciated!

Thanks,
Russell

#include <boost/function.hpp>
#include <iostream>

class MHBAccessor {
     template<class> friend class MHBase;
     template<class Derived>
     static int foo(Derived& derived, int i) { return derived.foo_(i); }
};

typedef boost::function<int (int)> FooFunc;

template <class Derived>
struct MHBase {
     Derived& derived() { return static_cast<Derived&>(*this); }

     int foo(int i) { return MHBAccessor::foo(this->derived(), i); }

     template <template <class> class MHBase >
     struct fooFO {
         fooFO(MHBase<Derived>& mhb) : mhb_(mhb) {}
         void operator()(int i) { mhb_.foo(i); }
     private:
         MHBase<Derived>& mhb_;
     };

     FooFunc getFooFunc() {
         FooFunc ff = fooFO<MHBase<Derived> >(*this);
         return ff;
     }
};

class Put : public MHBase<Put>
{
     friend class MHBAccessor;
     int foo_(int i) { return i; }
};

int main(int argc, char **argv)
{
     Put put;
     std::cout << put.foo(123) << std::endl;
     FooFunc ff = put.getFooFunc();
     std::cout << ff(456) << std::endl;
     return 0;
}


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