template and forward declaration

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jobseeker

    template and forward declaration

    From: jobseeker95479@ yahoo.com (jobseeker)
    Newsgroups: comp.lang.c++.m oderated
    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)(S oftkey *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)(S oftKey *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)(Te stKey *key, void *);

    or

    template<class Type>
    typedef int (* pfncDrawCap)(Te stKey<Type> *key, void *);

    but I still get an error. Can anyone throw some light into this?
  • Julián Albo

    #2
    Re: template and forward declaration

    jobseeker escribió:
    [color=blue]
    > I have tried with
    >
    > template<class Type>
    > typedef int (* pfncDrawCap)(Te stKey *key, void *);
    >
    > or
    >
    > template<class Type>
    > typedef int (* pfncDrawCap)(Te stKey<Type> *key, void *);
    >
    > but I still get an error. Can anyone throw some light into this?[/color]

    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.

    Comment

    • DarkSpy

      #3
      Re: template and forward declaration

      Julián Albo <JULIANALBO@ter ra.es> wrote in message news:<3F8C73C1. B3A384EA@terra. es>...[color=blue]
      > jobseeker escribi :
      >[color=green]
      > > I have tried with
      > >[/color]
      >[color=green]
      > > template<class Type>
      > > typedef int (* pfncDrawCap)(Te stKey *key, void *);
      > >[/color]
      >[color=green]
      > > or
      > >[/color]
      >[color=green]
      > > template<class Type>
      > > typedef int (* pfncDrawCap)(Te stKey<Type> *key, void *);
      > >[/color]
      >[color=green]
      > > but I still get an error. Can anyone throw some light into this?[/color]
      >
      > 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.[/color]

      the current is: DrawCap<Type>:: pfnc; for ex:
      DrawCap<int>::p fnc
      [color=blue]
      >
      > Regards.[/color]

      Comment

      Working...