template instantiation syntax

Discussion in 'C++' started by Faheem Mitha, Oct 30, 2005.

  1. Faheem Mitha

    Faheem Mitha Guest

    Hi,

    On the net, I found the following article,
    http://www.gamedev.net/reference/articles/article2097.asp

    describing a generic factory class.

    My question is about one of the links pointed to by the article,
    namely

    http://downloads.gamedev.net/features/programming/objectfactory/listing4.h

    The code in listing4.h includes syntax like

    ****************************************************************************
    template<typename BaseClassType, typename Param1Type, typename UniqueIdType>
    class ObjectFactory<BaseClassType (Param1Type), UniqueIdType>
    {
    protected:
    typedef BaseClassType (*CreateObjectFunc)(Param1Type);
    [...]
    ****************************************************************************

    From the article, it looks like he is using the structure of templates
    parameters after the class name to instantiate the template, eg.

    ObjectFactory<Shape *(int), std::string> shape_factory;

    Here Shape * == BaseClassType
    int == Param1Type
    std::string == UniqueIdType

    I've never seen syntax like this, so I'm wondering what is going
    on. Does anyone have an idea? Is this even legal C++ syntax?

    Thanks in advance. Faheem.
     
    Faheem Mitha, Oct 30, 2005
    #1
    1. Advertising

  2. Faheem Mitha

    Faheem Mitha Guest

    On Sun, 30 Oct 2005 17:53:54 GMT, Faheem Mitha <> wrote:
    > Hi,
    >
    > On the net, I found the following article,
    > http://www.gamedev.net/reference/articles/article2097.asp
    >
    > describing a generic factory class.
    >
    > My question is about one of the links pointed to by the article,
    > namely
    >
    > http://downloads.gamedev.net/features/programming/objectfactory/listing4.h
    >
    > The code in listing4.h includes syntax like
    >
    > ****************************************************************************
    > template<typename BaseClassType, typename Param1Type, typename UniqueIdType>
    > class ObjectFactory<BaseClassType (Param1Type), UniqueIdType>
    > {
    > protected:
    > typedef BaseClassType (*CreateObjectFunc)(Param1Type);
    > [...]
    > ****************************************************************************
    >
    > From the article, it looks like he is using the structure of templates
    > parameters after the class name to instantiate the template, eg.
    >
    > ObjectFactory<Shape *(int), std::string> shape_factory;
    >
    > Here Shape * == BaseClassType
    > int == Param1Type
    > std::string == UniqueIdType


    I missed the

    template <typename CtorSignature, typename UniqueIdType> class ObjectFactory;

    at the top. So this is a class-template partial specialization of
    ObjectFactory, though not of a kind I have seen before.

    Have I understood this correctly?

    Thanks. Faheem.
     
    Faheem Mitha, Oct 30, 2005
    #2
    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. Fernando Cuenca
    Replies:
    4
    Views:
    2,550
    Gianni Mariani
    Sep 6, 2004
  2. Thomas Maier-Komor
    Replies:
    6
    Views:
    648
    Thomas Maier-Komor
    May 19, 2005
  3. Replies:
    1
    Views:
    610
    Salt_Peter
    Dec 25, 2006
  4. Ed
    Replies:
    1
    Views:
    356
  5. Noah Roberts
    Replies:
    6
    Views:
    1,220
    Johannes Schaub (litb)
    Feb 2, 2011
Loading...

Share This Page