template and forward declaration

J

jobseeker

From: (e-mail address removed) (jobseeker)
Newsgroups: comp.lang.c++.moderated
Subject: template and forward declaration
NNTP-Posting-Host: 131.233.150.22

I have defined a class that contains a data member of a function type.
The signature of the function type take a pointer of the class itself
as a parameter:

class Softkey; // forward declaration

typedef int (* pfncOnSelect)(Softkey *key, void *);

class Softkey
{

...
int value;
pfncOnSelect m_OnSelect;
...
};

This class is compiled and run successfully without error. The
problem I have now is that I am trying to modify this class into a
templated class as follows:

template<class Type>
class SoftKey; // forward declaration.

typedef int (* pfncOnSelect)(SoftKey *key, void *);

template<class Type>
class Softkey
{

...
Type value;
pfncOnSelect m_OnSelect;
...
};

Now the compiler complains about syntax error in the typedef line.
I have tried with

template<class Type>
typedef int (* pfncDrawCap)(TestKey *key, void *);

or

template<class Type>
typedef int (* pfncDrawCap)(TestKey<Type> *key, void *);

but I still get an error. Can anyone throw some light into this?
 
?

=?iso-8859-1?Q?Juli=E1n?= Albo

jobseeker escribió:
I have tried with

template<class Type>
typedef int (* pfncDrawCap)(TestKey *key, void *);

or

template<class Type>
typedef int (* pfncDrawCap)(TestKey<Type> *key, void *);

but I still get an error. Can anyone throw some light into this?

The language does not allow templatized typedef. You can do something
like:

template <class Type>
struct DrawCap {
typedef int (* pfnc) (TestKey <Type> * key, void *);
};

And use the type DrawCap::pfnc.

Regards.
 
D

DarkSpy

Julián Albo said:
jobseeker escribi :




The language does not allow templatized typedef. You can do something
like:

template <class Type>
struct DrawCap {
typedef int (* pfnc) (TestKey <Type> * key, void *);
};

And use the type DrawCap::pfnc.

the current is: DrawCap<Type>::pfnc; for ex:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top