Hallo group,
VC6 gives me an error in the marked row of the code snippet below:
error C2664: 'defineIOHandle r' : conversion of parameter 3 from 'bool
(class Qwt3D::Plot3D *,const char *)' to 'bool (__cdecl *)(class
Qwt3D::Plot3D *,const char *)' not possible.
The culprit is the pointer to the specialization of writeQt. On the
other hand, if I use a function pointer to the following function no
error occurs during compilation:
bool writeQtNoTempla te(Qwt3D::Plot3 D* plot, const char* fname)
{...}
The 3th argument argument in defineIOHandler is a function pointer
defined as follows:
// ... typedef inside a traits class
typedef bool (*ioroutine)( T*, const char* fname );
2nd question:
The inline statement prevents linker errors regarding multiple defined
functions. How is the rule for templates here ? IMO it is highly
possible that the function becomes actually not inlined (contains a
loop). Is this 'hack' sure in the sense, that it should always enforce
uniqueness of the function?
TIA,
Micha
--- snip --
struct StringMap
{
static std::vector<QSt ring> smap;
};
template <typename SMAP, int IDX>
bool writeQt(Qwt3D:: Plot3D* plot, const char* fname)
{
if (!plot)
return false;
QImage im = plot->grabFrameBuffe r(true);
return im.save(fname, SMAP::smap[IDX]);
}
inline void defineQtIOHandl er()
{
static StringMap sm;
for ( int i = 0; i < QImageIO::outpu tFormats().coun t(); i++ )
{
QString format = QString( QImageIO::outpu tFormats().at( i ) );
StringMap::smap .push_back(form at);
// error begin
defineIOHandler <Qwt3D::Plot3D> ( format, 0, writeQt<StringM ap,i>);
//error end
}
}
--- snap ---
VC6 gives me an error in the marked row of the code snippet below:
error C2664: 'defineIOHandle r' : conversion of parameter 3 from 'bool
(class Qwt3D::Plot3D *,const char *)' to 'bool (__cdecl *)(class
Qwt3D::Plot3D *,const char *)' not possible.
The culprit is the pointer to the specialization of writeQt. On the
other hand, if I use a function pointer to the following function no
error occurs during compilation:
bool writeQtNoTempla te(Qwt3D::Plot3 D* plot, const char* fname)
{...}
The 3th argument argument in defineIOHandler is a function pointer
defined as follows:
// ... typedef inside a traits class
typedef bool (*ioroutine)( T*, const char* fname );
2nd question:
The inline statement prevents linker errors regarding multiple defined
functions. How is the rule for templates here ? IMO it is highly
possible that the function becomes actually not inlined (contains a
loop). Is this 'hack' sure in the sense, that it should always enforce
uniqueness of the function?
TIA,
Micha
--- snip --
struct StringMap
{
static std::vector<QSt ring> smap;
};
template <typename SMAP, int IDX>
bool writeQt(Qwt3D:: Plot3D* plot, const char* fname)
{
if (!plot)
return false;
QImage im = plot->grabFrameBuffe r(true);
return im.save(fname, SMAP::smap[IDX]);
}
inline void defineQtIOHandl er()
{
static StringMap sm;
for ( int i = 0; i < QImageIO::outpu tFormats().coun t(); i++ )
{
QString format = QString( QImageIO::outpu tFormats().at( i ) );
StringMap::smap .push_back(form at);
// error begin
defineIOHandler <Qwt3D::Plot3D> ( format, 0, writeQt<StringM ap,i>);
//error end
}
}
--- snap ---
Comment