473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Pointer to member as template argument

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
3 1533
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexander Stippler | last post by:
Can someone explain the following construct to me: What is not clear to me is what the argument to foo is. A pointer to a member? template <class U> static char foo(void (U::*)(void)); ...
3
by: jimjim | last post by:
Hello, My question concerns as to how a pointer is passed by reference as a function argument. The following is from code taken from the MICO implementation of the CORBA specification. in...
4
by: Gert Van den Eynde | last post by:
Hi all, A beginners question.... I've got a template class template <class T> classA {...} In an other class, I want to pass a pointer to an instance of classA as a function argument....
15
by: Albert | last post by:
Hi, I need to pass a pointer-to-member-function as a parameter to a function which takes pointer-to-function as an argument. Is there any way to do it besides overloading the function? Here...
4
by: firegun9 | last post by:
Hello everyone, here is my program: /////////////////////////////// #include <iostream> using namespace std; void multi(double* arrayPtr, int len){ for(int i=0; i<len; i++)...
1
by: Adam Dziendziel | last post by:
Hi all! I'm writing a luabind/boost::python-like binding utility for a Squirrel language to generating wrapper-functions for C++ classes and have a problem with passing the pointer-to-member...
4
by: Damien | last post by:
Hi all, I've run into something confusing on MS VC6. Yeah I know it's old but that's what the client wants, so... I'm trying to pass a pointer to a member function as a template argument,...
0
by: ivan.leben | last post by:
I am writing this in a new thread to alert that I found a solution to the problem mentioned here: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8 and to avoid...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
1
by: autumn | last post by:
Hi everybody, I'm having problem passing pointer to member object as template argument, seems VC 2005 does not allow 'pointer to base member' to 'pointer to derived member' conversion in template...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.