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<class Derived> template<class> class MHBase> struct MHBase<
<template-parameter-1-1> >::fooFO
Any help appreciated!
Thanks,
Russell
#include
#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 FooFunc;
template <class Derived>
struct MHBase {
Derived& derived() { return static_cast(*this); }
int foo(int i) { return MHBAccessor::foo(this->derived(), i); }
template
struct fooFO {
fooFO(MHBase<Derived>& mhb) : mhb_(mhb) {}
void operator()(int i) { mhb_.foo(i); }
private:
MHBase<Derived>& mhb_;
};
FooFunc getFooFunc() {
FooFunc ff = fooFO(*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;
}