473,405 Members | 2,287 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,405 software developers and data experts.

Function pointers in typedef templates under Linux

Hi,

I have a problem compiling the next piece of code under Linux using g++
(both 3.4.3 and 4.0.1)

template<typename T>
class Table{
public:
// typedef T (TBoxTest::*GetterType)();
typedef T (*Type)();
};

It should provide a typedef to a function pointer of which the return
type is defined by the template argument. Both the line which is
commented out and the line under it gives the next error message in
g++;

error: ISO C++ forbids declaration of `Type' with no type

Does anyone have any idea how to solve this?

Kind regards,
Mark Schroders

Sep 27 '05 #1
3 4655
Bl*****@yahoo.com wrote:
I have a problem compiling the next piece of code under Linux using g++
(both 3.4.3 and 4.0.1)

template<typename T>
class Table{
public:
// typedef T (TBoxTest::*GetterType)();
typedef T (*Type)();
};

It should provide a typedef to a function pointer of which the return
type is defined by the template argument. Both the line which is
commented out and the line under it gives the next error message in
g++;

error: ISO C++ forbids declaration of `Type' with no type

Does anyone have any idea how to solve this?


You should ask in gnu.g++.help, since it seems to be specific to your
compiler. This

struct Foo {};

template<typename T>
class Table {
public:
// typedef T (TBoxTest::*GetterType)();
typedef T (*Type)();
};

int main() {
Table<Foo> tfoo;
}

compiles just fine with Comeau online and VC++ v7.1, for example. Maybe
upgrading to a later version of g++ would help...

V
Sep 27 '05 #2
Hi,

mybe I can give you a clue. Right now I'm too busy to test how
exactly it should be applied to your problem, but it seems to me
like the keyword "typename" is missing.

I think I solved the same problem in one of my template
classes recently :

template <class T>
class GroupParent : public T {
protected:
list<T*> children;
bool flat;
public:
typedef typename list<T*>::const_iterator const_iterator;
typedef typename list<T*>::iterator iterator;

.......

I'm far from beeing a c++ pro ... but your typedef looks a bit strange
to me ... anyway - good luck

Micha

Sep 27 '05 #3
You were right. The problem I had appears to be caused in a totally
different part of my program. This though this is the only error
message I got.

Thanks!

Sep 28 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian | last post by:
Hi all, I am implementing an object that is currently using function pointers for callbacks to let me do something on assignment: template <class T> class MyClass{ private: typedef T& (*...
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
3
by: Jan-Henrik Grobe | last post by:
Hallo, I am coming to this newsgroup with a very strange Problem. I have two c++ files A.cpp and B.cpp....In A.cpp I am creating an openGL window and in B.cpp I have stored the callback...
4
by: Aaron Walker | last post by:
Greetings, I'm attempting to write my first *real* template function that also deals with a map of strings to member function pointers that is making the syntax a little tricky to get right. ...
4
by: Erik Wikström | last post by:
In school (no I will not ask you to do my schoolwork for me) we talked about policy-based design and got an assignment where we got the a code- fragment from a stack-implementation. The idea with...
15
by: Daniel Rudy | last post by:
Hello, Consider the following code: /* resolve_hostname this resolves the hostname into an ip address. */ static void resolve_hostname(char result, const char hostname, const char server) {
5
by: DevarajA | last post by:
I'd like to create a linked list or a simple array of pointers to function, but I can't find out how. I'm trying to do it like this: struct fn_pointer{ void *pt_; /*the address*/ char...
2
by: Jack | last post by:
I have a chunk of code that loads a few dozen function pointers into global variables. I'm concerned with unused memory consumption. What if the client only needs to use one or two functions? Then...
15
by: bwaichu | last post by:
I'm struggling with the concept of function pointers. I understand that a function pointer contains the memory address of the function. But I'm not sure how they are effectively used, and I'm not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.