M
ma740988
I was perusing modern C++ designs and the loki library and I might add
I hit overload when I hit select part of that book and the library.
The template _stuff_ is very intense ...... whew!!
Oso long ago I found - for the most part a nice callback class.
Current approach works well for functions that accept no argments.
Trouble is I now need to tweak the code to accomodate the case for an
integer argument. How could I achieve this?
// file sltest.h
#ifndef SLTEST_H
#define SLTEST_H
class CallbackBase
{
public:
virtual void operator()() const { };
virtual ~CallbackBase() = 0;
};
CallbackBase::~CallbackBase() { }
template<typename T>
class Callback : public CallbackBase
{
public:
typedef void (T::*F)();
Callback( T& t, F f ) : t_(&t), f_(f) { }
void operator()() const { (t_->*f_)(); }
private:
T* t_;
F f_;
};
template<typename T>
Callback<T> make_callback( T& t, void (T::*f) () )
{
return Callback<T>( t, f );
}
// std::auto_ptr version ... akin to the above
If it's in the two hard pile then I'll end up having to go study the
loki library and re-read those chapters of Modern C++ design
Thanks
I hit overload when I hit select part of that book and the library.
The template _stuff_ is very intense ...... whew!!
Oso long ago I found - for the most part a nice callback class.
Current approach works well for functions that accept no argments.
Trouble is I now need to tweak the code to accomodate the case for an
integer argument. How could I achieve this?
// file sltest.h
#ifndef SLTEST_H
#define SLTEST_H
class CallbackBase
{
public:
virtual void operator()() const { };
virtual ~CallbackBase() = 0;
};
CallbackBase::~CallbackBase() { }
template<typename T>
class Callback : public CallbackBase
{
public:
typedef void (T::*F)();
Callback( T& t, F f ) : t_(&t), f_(f) { }
void operator()() const { (t_->*f_)(); }
private:
T* t_;
F f_;
};
template<typename T>
Callback<T> make_callback( T& t, void (T::*f) () )
{
return Callback<T>( t, f );
}
// std::auto_ptr version ... akin to the above
If it's in the two hard pile then I'll end up having to go study the
loki library and re-read those chapters of Modern C++ design
Thanks