473,412 Members | 4,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

template and forward declaration

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
2 14129
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Yoon-Soo Lee | last post by:
I am using Visual C++ .NET 2003 and running into some linking error from the following template code. The error messages is error LNK2019: unresolved external symbol "class...
5
by: Trevor Lango | last post by:
What is the appropriate syntax for placing a friend function that includes as one of it's parameters a pointer to the class object itself within the template class? I have the following: ...
2
by: Nobody | last post by:
what is the syntax for a forward declaration of a template class? normally I declare all my classes at the top of the header: class CClass1; class CClass2; class CClass1 : public CBase {
5
by: Nomak | last post by:
Hello all, i have two template classes which needs each other. I tried to write some fwd decl / decl / impl in a good way but i can't get it to compile. Explanations: - .hh files are for...
2
by: Ruben Campos | last post by:
I have a problem with a template function that is declared as a friend of a template class. I'll first show the exact problem with source code: // MyClass.hpp template <typename T> class...
2
by: verec | last post by:
Consider a first version: --- drawable.hpp --- #include "gcdata.hpp" struct drawable { ... virtual int internal_new_GC(gcdata * gcd) = 0 ; } ; --- gcdata.hpp ---
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
4
by: StephQ | last post by:
According to: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.4 , if my understanding is correct, in template<typename T> class Foo { friend void func (const Foo<T>& foo); }; ...
8
by: Tim Frink | last post by:
Hi, I want to use a callback function together with templates. Let's say I've this code: File a.h: class A { private:
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.