Function pointers in typedef templates under Linux

B

Blaless

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
 
V

Victor Bazarov

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
 
M

Micha

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
 
B

Blaless

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!
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top