D
Drew
I have the following code in a header file (pseudocode):
template <class T>
class Pt3 : public Vec3<T>
{
public:
// Constructors
Pt3() {}
void setVertFcn( void (*vf)(T x, T y, T z)) { vertfcn = vf; }
}
and in another header:
class SplineCurve
{
public:
CurveD() { Pt3<double> pt; pt.setVertFcn( glVertex3d); }
}
Compiler complains:
error C2664: 'Pt3<T>::setVertFcn' : cannot convert parameter 1 from 'void
(GLdouble,GLdouble,GLdouble)' to 'void (__cdecl *)(T,T,T)'
with
[
T=double
]
and
[
T=double
]
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
So following the compilers suggestion:
SplineCurveD() { Pt3<double> pt; pt.setVertFcn( (void (__cdecl
*)(T,T,T))&glVertex3d); }
Error becomes:
error C2664: 'Pt3<T>::setVertFcn' : cannot convert parameter 1 from 'void
(__cdecl *)(T,T,T)' to 'void (__cdecl *)(T,T,T)'
with
[
T=double
]
and
[
T=double
]
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
What's the right way to do this cast?
Thanks,
Drew
template <class T>
class Pt3 : public Vec3<T>
{
public:
// Constructors
Pt3() {}
void setVertFcn( void (*vf)(T x, T y, T z)) { vertfcn = vf; }
}
and in another header:
class SplineCurve
{
public:
CurveD() { Pt3<double> pt; pt.setVertFcn( glVertex3d); }
}
Compiler complains:
error C2664: 'Pt3<T>::setVertFcn' : cannot convert parameter 1 from 'void
(GLdouble,GLdouble,GLdouble)' to 'void (__cdecl *)(T,T,T)'
with
[
T=double
]
and
[
T=double
]
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
So following the compilers suggestion:
SplineCurveD() { Pt3<double> pt; pt.setVertFcn( (void (__cdecl
*)(T,T,T))&glVertex3d); }
Error becomes:
error C2664: 'Pt3<T>::setVertFcn' : cannot convert parameter 1 from 'void
(__cdecl *)(T,T,T)' to 'void (__cdecl *)(T,T,T)'
with
[
T=double
]
and
[
T=double
]
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
What's the right way to do this cast?
Thanks,
Drew