Template class Compile problem



 DEVELOP > c-Plus-Plus > Template class Compile problem

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "hyderabadblues"
Date: 31 Jan 2008 02:21:56 AM
Object: Template class Compile problem
I have created a timer class which is a template, but when I tried to
to create an object , I am getting following compile time error
template<class T>class prefetcher_tclTimer
{
typedef tVoid (T::*PMEMFUNC)();
private:
T* m_poClient; // Pointer to calling class
PMEMFUNC m_pMemFunc;
tU32 _u32Timeout;
tU32 _u32TimerInterval;
static void vOnTimeout( tPVoid arg );
tclTrace *m_poTrace;
public:
// Public functions
// connstructor / destructor
prefetcher_tclTimer ( );
~prefetcher_tclTimer( );
tBool Create( tU32 u32TimerMSec, tU32 u32TimerIntervalMSec,
T* _poClient, PMEMFUNC _pMemFunc );
tBool bStart( );
tBool bReset( );
tBool bStop ( );
};
I have defined the function bStart as
tBool prefetcher_tclTimer::bStart( )
{
tS32 s32RetVal;
if( _phTimerHandle != INVALID_HANDLE )
{
m_poTrace->vInfo(" prefetcher_tclTimer::bStart "):
s32RetVal = s32TimerSetTime( _phTimerHandle, _u32Timeout,
_u32TimerInterval );
if( s32RetVal != OK )
{
m_poTrace->vInfo("prefetcher_tclTimer::bStart( ), Timer Set
Failed");
}
}
else
{
m_poTrace->vInfo("prefetcher_tclTimer::bStart( ), Invalid Timer
Handler");
s32RetVal = FALSE;
}
return (tBool)s32RetVal;
}
I am getting an error as when tried to to compile it, I am creating
the template object with parameter tclUsbDataBuffer
Error: L6218E: Undefined symbol
prefetcher_tclTimer<tclUsbDataBuffer>::bStart() (referred from
usbDataBuffer.o).
.

User: "Mark"

Title: Re: Template class Compile problem 31 Jan 2008 02:55:16 AM
On Jan 31, 12:21 am, hyderabadblues <sirishku...@gmail.com> wrote:

I have created a timer class which is a template, but when I tried to
to create an object , I am getting following compile time error

template<class T>class prefetcher_tclTimer
{
typedef tVoid (T::*PMEMFUNC)();

private:
T* m_poClient; // Pointer to calling class
PMEMFUNC m_pMemFunc;
tU32 _u32Timeout;
tU32 _u32TimerInterval;
static void vOnTimeout( tPVoid arg );
tclTrace *m_poTrace;

public:
// Public functions
// connstructor / destructor
prefetcher_tclTimer ( );
~prefetcher_tclTimer( );

tBool Create( tU32 u32TimerMSec, tU32 u32TimerIntervalMSec,
T* _poClient, PMEMFUNC _pMemFunc );
tBool bStart( );
tBool bReset( );
tBool bStop ( );

};

I have defined the function bStart as

tBool prefetcher_tclTimer::bStart( )
{
tS32 s32RetVal;

if( _phTimerHandle != INVALID_HANDLE )
{
m_poTrace->vInfo(" prefetcher_tclTimer::bStart "):

s32RetVal = s32TimerSetTime( _phTimerHandle, _u32Timeout,
_u32TimerInterval );
if( s32RetVal != OK )
{
m_poTrace->vInfo("prefetcher_tclTimer::bStart( ), Timer Set
Failed");
}
}
else
{
m_poTrace->vInfo("prefetcher_tclTimer::bStart( ), Invalid Timer
Handler");
s32RetVal = FALSE;
}
return (tBool)s32RetVal;

}

I am getting an error as when tried to to compile it, I am creating
the template object with parameter tclUsbDataBuffer

Error: L6218E: Undefined symbol
prefetcher_tclTimer<tclUsbDataBuffer>::bStart() (referred from
usbDataBuffer.o).

The simple answer is to put the entire function (including
definitions) in the .h file. There's a reason for this, but I'd
probably screw up the explanation quite horribly and you're better to
google it.
.
User: "Mark"

Title: Re: Template class Compile problem 31 Jan 2008 03:01:23 AM
On Jan 31, 12:55 am, Mark <mnbaya...@gmail.com> wrote:

On Jan 31, 12:21 am, hyderabadblues <sirishku...@gmail.com> wrote:



I have created a timer class which is a template, but when I tried to
to create an object , I am getting following compile time error


template<class T>class prefetcher_tclTimer
{
typedef tVoid (T::*PMEMFUNC)();


private:
T* m_poClient; // Pointer to calling class
PMEMFUNC m_pMemFunc;
tU32 _u32Timeout;
tU32 _u32TimerInterval;
static void vOnTimeout( tPVoid arg );
tclTrace *m_poTrace;


public:
// Public functions
// connstructor / destructor
prefetcher_tclTimer ( );
~prefetcher_tclTimer( );


tBool Create( tU32 u32TimerMSec, tU32 u32TimerIntervalMSec,
T* _poClient, PMEMFUNC _pMemFunc );
tBool bStart( );
tBool bReset( );
tBool bStop ( );


};


I have defined the function bStart as


tBool prefetcher_tclTimer::bStart( )
{
tS32 s32RetVal;


if( _phTimerHandle != INVALID_HANDLE )
{
m_poTrace->vInfo(" prefetcher_tclTimer::bStart "):


s32RetVal = s32TimerSetTime( _phTimerHandle, _u32Timeout,
_u32TimerInterval );
if( s32RetVal != OK )
{
m_poTrace->vInfo("prefetcher_tclTimer::bStart( ), Timer Set
Failed");
}
}
else
{
m_poTrace->vInfo("prefetcher_tclTimer::bStart( ), Invalid Timer
Handler");
s32RetVal = FALSE;
}
return (tBool)s32RetVal;


}


I am getting an error as when tried to to compile it, I am creating
the template object with parameter tclUsbDataBuffer


Error: L6218E: Undefined symbol
prefetcher_tclTimer<tclUsbDataBuffer>::bStart() (referred from
usbDataBuffer.o).


The simple answer is to put the entire function (including
definitions) in the .h file. There's a reason for this, but I'd
probably screw up the explanation quite horribly and you're better to
google it.

Actually, I'll give it a shot.
prefetcher_tclTimer<tclUsbDataBuffer>::bStart() is declared in
your .h file, but never defined (for tclUsbDataBuffer). When the
compiler sees prefetcher_tclTimer<tclUsbDataBuffer>::bStart() for the
first time, it needs to find the templated definition for it, and then
generate a function specifically for tclUsbDataBuffer. However, since
the compiler only has a declaration and not a definition at this
point, it can't do that.
.
User: "hyderabadblues"

Title: Re: Template class Compile problem 31 Jan 2008 04:40:07 AM
On Jan 31, 2:01 pm, Mark <mnbaya...@gmail.com> wrote:

On Jan 31, 12:55 am, Mark <mnbaya...@gmail.com> wrote:



On Jan 31, 12:21 am, hyderabadblues <sirishku...@gmail.com> wrote:


I have created a timer class which is a template, but when I tried to
to create an object , I am getting following compile time error


template<class T>class prefetcher_tclTimer
{
typedef tVoid (T::*PMEMFUNC)();


private:
T* m_poClient; // Pointer to calling class
PMEMFUNC m_pMemFunc;
tU32 _u32Timeout;
tU32 _u32TimerInterval;
static void vOnTimeout( tPVoid arg );
tclTrace *m_poTrace;


public:
// Public functions
// connstructor / destructor
prefetcher_tclTimer ( );
~prefetcher_tclTimer( );


tBool Create( tU32 u32TimerMSec, tU32 u32TimerIntervalMSec,
T* _poClient, PMEMFUNC _pMemFunc );
tBool bStart( );
tBool bReset( );
tBool bStop ( );


};


I have defined the function bStart as


tBool prefetcher_tclTimer::bStart( )
{
tS32 s32RetVal;


if( _phTimerHandle != INVALID_HANDLE )
{
m_poTrace->vInfo(" prefetcher_tclTimer::bStart "):


s32RetVal = s32TimerSetTime( _phTimerHandle, _u32Timeout,
_u32TimerInterval );
if( s32RetVal != OK )
{
m_poTrace->vInfo("prefetcher_tclTimer::bStart( ), Timer Set
Failed");
}
}
else
{
m_poTrace->vInfo("prefetcher_tclTimer::bStart( ), Invalid Timer
Handler");
s32RetVal = FALSE;
}
return (tBool)s32RetVal;


}


I am getting an error as when tried to to compile it, I am creating
the template object with parameter tclUsbDataBuffer


Error: L6218E: Undefined symbol
prefetcher_tclTimer<tclUsbDataBuffer>::bStart() (referred from
usbDataBuffer.o).


The simple answer is to put the entire function (including
definitions) in the .h file. There's a reason for this, but I'd
probably screw up the explanation quite horribly and you're better to
google it.


Actually, I'll give it a shot.

prefetcher_tclTimer<tclUsbDataBuffer>::bStart() is declared in
your .h file, but never defined (for tclUsbDataBuffer). When the
compiler sees prefetcher_tclTimer<tclUsbDataBuffer>::bStart() for the
first time, it needs to find the templated definition for it, and then
generate a function specifically for tclUsbDataBuffer. However, since
the compiler only has a declaration and not a definition at this
point, it can't do that.

Thanks It solves my problem, But still i face problem one I have a
static function pointer which I intialize during template object
creation how should I declare the static function pointer
typedef tVoid (T::*PMEMFUNC)();
static PMEMFUNC m_pMemFunc;
//How should I declare m_pMemFunc because it is static.
.




  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER