* static function pointers in C++ template class
@ 2007-02-18 0:46 Wesley Smith
2007-02-18 1:37 ` Wesley Smith
0 siblings, 1 reply; 2+ messages in thread
From: Wesley Smith @ 2007-02-18 0:46 UTC (permalink / raw)
To: gcc-help
Hi,
I'm trying to figure out the proper syntax for setting static member
variables of a C++ template class that are function pointers. The
warnings from gcc don't really give any insight and a search of the
web turns up things that are close but not quite what I'm looking for.
Here's the code:
template <class T>
class udata
{
public:
//stuff
protected:
static void (*kill_func)(T); //my function pointer
};
//create specializations as well a general case
template <class T>
void (udata<T>::*kill_func)(T) = free;
template <dWorldID>
void (udata<dWorldID>::*kill_func)(dWorldID) = dWorldDestroy;
template <dSpaceID>
void (udata<dSpaceID>::*kill_func)(dSpaceID) = dSpaceDestroy;
The errors I'm getting are:
/Users/wesleysmith/jit.gl.lua_beta1/Lua_dev/ODE_Package/lua_ode_udata.h:62:
error: template declaration of 'void (udata<T>::* kill_func)(T)'
/Users/wesleysmith/jit.gl.lua_beta1/Lua_dev/ODE_Package/lua_ode_udata.h:65:
error: template declaration of 'void (udata<dxWorld*>::*
kill_func)(dxWorld*)'
/Users/wesleysmith/jit.gl.lua_beta1/Lua_dev/ODE_Package/lua_ode_udata.h:68:
error: template declaration of 'void (udata<dxSpace*>::*
kill_func)(dxSpace*)'
where dxSpace* is the same as dSpaceID and dxWorld* is the same as dWorldID
Where is my syntax going wrong?
thanks,
wes
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: static function pointers in C++ template class
2007-02-18 0:46 static function pointers in C++ template class Wesley Smith
@ 2007-02-18 1:37 ` Wesley Smith
0 siblings, 0 replies; 2+ messages in thread
From: Wesley Smith @ 2007-02-18 1:37 UTC (permalink / raw)
To: gcc-help
So, I kind of figured it out. Now I'm seeing some strange behavior
with instantiation of templated classes that is dependent on the
position of the code in the file. If I have:
template <dSpaceID>
typename udata<dSpaceID>::fptr udata<dSpaceID>::kill_func = dSpaceDestroy;
template <dWorldID>
typename udata<dWorldID>::fptr udata<dWorldID>::kill_func = dWorldDestroy;
I get the error:
lua_ode.cpp:28: error: invalid conversion from 'void (*)(dxWorld*)' to
'void (*)(dxSpace*)'
If I swap the order of the 2 declarations, I get:
lua_ode.cpp:28: error: invalid conversion from 'void (*)(dxSpace*)' to
'void (*)(dxWorld*)'
Why would that happen? My gcc version is:
gcc version 4.0.1 (Apple Computer, Inc. build 5341)
thanks,
wes
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-02-18 0:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-18 0:46 static function pointers in C++ template class Wesley Smith
2007-02-18 1:37 ` Wesley Smith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).