Function pointers in typedef templates under Linux

Discussion in 'C++' started by Blaless@yahoo.com, Sep 27, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Sep 27, 2005
    #2
    1. Advertising

  3. Micha Guest

    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
     
    Micha, Sep 27, 2005
    #3
  4. Guest

    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, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop
    Replies:
    3
    Views:
    484
  2. Generic Usenet Account
    Replies:
    3
    Views:
    832
    Generic Usenet Account
    Jul 14, 2005
  3. Ben Pope
    Replies:
    4
    Views:
    367
    Neelesh Bodas
    Dec 6, 2005
  4. recover
    Replies:
    2
    Views:
    822
    recover
    Jul 25, 2006
  5. oor
    Replies:
    0
    Views:
    1,364
Loading...

Share This Page