template and forward declaration

Discussion in 'C++' started by jobseeker, Oct 14, 2003.

  1. jobseeker

    jobseeker Guest

    From: (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?
    jobseeker, Oct 14, 2003
    #1
    1. Advertising

  2. 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.
    =?iso-8859-1?Q?Juli=E1n?= Albo, Oct 14, 2003
    #2
    1. Advertising

  3. jobseeker

    DarkSpy Guest

    Julián Albo <> wrote in message news:<>...
    > 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.
    DarkSpy, Oct 15, 2003
    #3
    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. Nobody
    Replies:
    2
    Views:
    48,896
    Nobody
    Feb 12, 2004
  2. qazmlp
    Replies:
    1
    Views:
    576
    Jonathan Turkanis
    Feb 15, 2004
  3. verec
    Replies:
    2
    Views:
    1,001
    verec
    Jun 25, 2005
  4. steprobe
    Replies:
    3
    Views:
    473
    Vladimir Jovic
    Apr 7, 2010
  5. shaan
    Replies:
    2
    Views:
    526
    shaan
    Jul 2, 2012
Loading...

Share This Page