ma******@pegasus.cc.ucf.edu wrote:
[...]
I simply put it all in one file and fixed a couple of compile errors. I
really don't like doing that, but here you go, this compiles. No, I did
not try to run it.
I am not trying to judge it (and don't ask me to), but next time don't
post things that have to be put in separate files to be compiled. If it's
a language problem you have, spend some effort reducing your code to the
point where it's all in one module and exhibits the same error.
--------------------------------------------------
# include <cstdio>
# include <iostream>
# include <iomanip>
# include <stdlib.h>
# include <string>
# include <sstream>
# include <stdexcept>
# include <string>
# include <memory>
# include <functional>
# include <algorithm>
# include <iomanip>
# include <numeric>
# include <vector>
# include <list>
# include <map>
# include <ctime>
# include <bitset>
# include <typeinfo>
struct slDev
{
unsigned int slFabricId;
unsigned int slLinkId;
unsigned int slBridgeId;
void *arubaDev;
void *instance;
unsigned int pciIntAVector;
};
class test_base
{
public:
virtual void operator()(slDev *pslDevice_, unsigned int bell_val)
const {}
virtual ~test_base() = 0;
};
inline test_base::~test_base() {}
template<typename T> class cb : public test_base
{
public:
typedef void (T::*F)(slDev *pslDevice_, unsigned int bell_val);
cb(T& t, F f) : t_(&t), f_(f) {}
void operator()(slDev *pslDevice_, unsigned int bell_val) const
{
(t_->*f_)(pslDevice_, bell_val);
}
private:
T* t_;
F f_;
};
template<typename T> cb<T> make_callback(T& t, void (T::*f)(slDev
*pslDevice_, unsigned int bell_val))
{
return cb<T>(t, f);
}
template<class T>
std::auto_ptr<test_base> new_cb(T& t, void (T::*f)(slDev *pslDevice_,
unsigned int bell_val))
{
return std::auto_ptr<test_base>(new cb<T>(t, f));
}
class Base {
private:
static std::auto_ptr<test_base> user_cb_func;
protected:
template<typename T> Base( T& t, void (T::*f)(slDev *pslDevice_,
unsigned int bell_val))
{
user_cb_func = new_cb(t, f); // COMPLAINS ABOUT THIS >>>>>
}
public:
static void sl_callback_func(slDev *pslDevice_, unsigned int bell_val)
{
test_base& cb = *user_cb_func;
cb(pslDevice_, bell_val);
}
virtual ~Base() {}
};
class Derived : public Base {
private:
public:
template<typename T> Derived(T& t, void (T::*f)(slDev *pslDevice_,
unsigned int bell_val))
: Base(t, f)
{}
};
class sndr_exec
{
private:
Base *sndr_dy4;
slDev* pslDevice_;
public:
sndr_exec();
~sndr_exec();
void test_func();
void my_user_callback(slDev *pslDevice_, unsigned int door_bell);
};
std::auto_ptr<test_base> Base::user_cb_func;
sndr_exec::sndr_exec()
: sndr_dy4(new (std::nothrow) Derived (*this, &sndr_exec::my_user_callback))
, pslDevice_(0)
{
}
sndr_exec::~sndr_exec() {}
void sndr_exec::my_user_callback(slDev *pslDevice_, unsigned int door_bell)
{
std::cout << " this works YEAH " << std::endl;
std::cout << " door_bell " << door_bell << std::endl;
}
void sndr_exec::test_func()
{
sndr_dy4->sl_callback_func(pslDevice_, 99);
}
sndr_exec *sndr_exec_ = 0;
int main()
{
sndr_exec_ = new (std::nothrow) sndr_exec();
sndr_exec_->test_func();
delete sndr_exec_;
}