Connecting Tech Pros Worldwide Help | Site Map

template function problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 09:00 AM
Micha Bieber
Guest
 
Posts: n/a
Default template function problem

Hallo group,

VC6 gives me an error in the marked row of the code snippet below:

error C2664: 'defineIOHandler' : 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 writeQtNoTemplate(Qwt3D::Plot3D* 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<QString> smap;
};


template <typename SMAP, int IDX>
bool writeQt(Qwt3D::Plot3D* plot, const char* fname)
{
if (!plot)
return false;

QImage im = plot->grabFrameBuffer(true);
return im.save(fname, SMAP::smap[IDX]);
}

inline void defineQtIOHandler()
{
static StringMap sm;
for ( int i = 0; i < QImageIO::outputFormats().count(); i++ )
{
QString format = QString( QImageIO::outputFormats().at( i ) );
StringMap::smap.push_back(format);
// error begin
defineIOHandler<Qwt3D::Plot3D>( format, 0, writeQt<StringMap,i>);
//error end
}
}

--- snap ---


  #2  
Old July 22nd, 2005, 09:01 AM
Micha Bieber
Guest
 
Posts: n/a
Default Re: template function problem

Micha Bieber wrote:
[color=blue]
>
> 2nd question:
> The inline statement prevents linker errors regarding multiple defined
> functions. How is the rule for templates here ? IMO it is highly[/color]

Sorry, I had no templates in mind here, but a non-template global
function.

Micha
[color=blue]
> 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?
>[/color]

  #3  
Old July 22nd, 2005, 09:01 AM
Micha Bieber
Guest
 
Posts: n/a
Default Re: template function problem

Micha Bieber wrote:
[color=blue]
>
> 2nd question:
> The inline statement prevents linker errors regarding multiple defined
> functions. How is the rule for templates here ? IMO it is highly[/color]

Sorry, I had no templates in mind here, but a non-template global
function.

Micha
[color=blue]
> 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?
>[/color]

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.