By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,247 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,247 IT Pros & Developers. It's quick & easy.

template and forward declaration

P: n/a
From: jo************@yahoo.com (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?
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
Jul 19 '05 #2

P: n/a
Julián Albo <JU********@terra.es> wrote in message news:<3F***************@terra.es>...
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.


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

Regards.

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.