By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,407 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,407 IT Pros & Developers. It's quick & easy.

Pointer to member as template argument

P: n/a
Hi guys,

Heres my code:

#ifndef CTIMEOUT_H
#define CTIMEOUT_H

template<class T, void (T::*FPtr)() >
class CTimeoutCallback
{
public:

~CTimeoutCallback();
CTimeoutCallback(T& o);

void Callback();

private:
T *obj;
};
#endif

//// CPP file below

#include "Timeout.h"

template<class T, void (T::*FPtr)() >
CTimeoutCallback<T, FPtr>::CTimeoutCallback(T& o) : obj(&o)
{
}

template<class T, void (T::*FPtr)() >
void CTimeoutCallback<T, FPtr>::Callback()
{
(obj->*FPtr)();
}
/// I trying to use it like this

CTestClass test;

CTimeoutCallback<CTestClass, &CTestClass::Printtimeout(test);
timeout.Callback();
However I'm getting the following errors:

Undefined symbol: 'CTimeoutCallback<class CTestClass, &void
CTestClass::Print(void)>::~CTimeoutCallback<class CTestClass, &void
CTestClass::Print(void)>(void)
(??1?$CTimeoutCallback@VCTestClass@@$1?Print@1@QAE XXZ@@QAE@XZ)'
Can anybody see my mistakes?
--
// morten
Mar 14 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Morten V Pedersen wrote:
class CTimeoutCallback
{
public:
you did not define this
~CTimeoutCallback();
CTimeoutCallback(T& o);

void Callback();

private:
T *obj;
};

However I'm getting the following errors:

Undefined symbol: 'CTimeoutCallback<class CTestClass, &void
CTestClass::Print(void)>::~CTimeoutCallback<class CTestClass, &void
CTestClass::Print(void)>(void)
(??1?$CTimeoutCallback@VCTestClass@@$1?Print@1@QAE XXZ@@QAE@XZ)'
Can anybody see my mistakes?
Your error indicates that your desctructor is not defined.

HTH
Mar 14 '07 #2

P: n/a
On Mar 14, 2:34 pm, Morten V Pedersen <m...@kom.aau.dkwrote:
Hi guys,

Heres my code:

#ifndef CTIMEOUT_H
#define CTIMEOUT_H

template<class T, void (T::*FPtr)() >
class CTimeoutCallback
{
public:

~CTimeoutCallback();
CTimeoutCallback(T& o);

void Callback();

private:
T *obj;
};
#endif

//// CPP file below

#include "Timeout.h"

template<class T, void (T::*FPtr)() >
CTimeoutCallback<T, FPtr>::CTimeoutCallback(T& o) : obj(&o)
{
}

template<class T, void (T::*FPtr)() >
void CTimeoutCallback<T, FPtr>::Callback()
{
(obj->*FPtr)();
}

/// I trying to use it like this

CTestClass test;

CTimeoutCallback<CTestClass, &CTestClass::Printtimeout(test);
timeout.Callback();

However I'm getting the following errors:

Undefined symbol: 'CTimeoutCallback<class CTestClass, &void
CTestClass::Print(void)>::~CTimeoutCallback<class CTestClass, &void
CTestClass::Print(void)>(void)
(??1?$CTimeoutCallback@VCTestClass@@$1?Print@1@QAE XXZ@@QAE@XZ)'

Can anybody see my mistakes?
Yes, you declared but did not define your destructor.

Cheers! --M

Mar 14 '07 #3

P: n/a
mlimber wrote:
On Mar 14, 2:34 pm, Morten V Pedersen <m...@kom.aau.dkwrote:
>Hi guys,

Heres my code:

#ifndef CTIMEOUT_H
#define CTIMEOUT_H

template<class T, void (T::*FPtr)() >
class CTimeoutCallback
{
public:

~CTimeoutCallback();
CTimeoutCallback(T& o);

void Callback();

private:
T *obj;
};
#endif

//// CPP file below

#include "Timeout.h"

template<class T, void (T::*FPtr)() >
CTimeoutCallback<T, FPtr>::CTimeoutCallback(T& o) : obj(&o)
{
}

template<class T, void (T::*FPtr)() >
void CTimeoutCallback<T, FPtr>::Callback()
{
(obj->*FPtr)();
}

/// I trying to use it like this

CTestClass test;

CTimeoutCallback<CTestClass, &CTestClass::Printtimeout(test);
timeout.Callback();

However I'm getting the following errors:

Undefined symbol: 'CTimeoutCallback<class CTestClass, &void
CTestClass::Print(void)>::~CTimeoutCallback<cla ss CTestClass, &void
CTestClass::Print(void)>(void)
(??1?$CTimeoutCallback@VCTestClass@@$1?Print@1@QA EXXZ@@QAE@XZ)'

Can anybody see my mistakes?

Yes, you declared but did not define your destructor.

Cheers! --M

Ok, I'm totally blind - now it works thx guys!

--
// morten
Mar 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.