C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

template instantiation syntax

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Faheem Mitha
Guest





PostPosted: Sun Oct 30, 2005 5:53 pm    Post subject: template instantiation syntax Reply with quote



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.
Back to top
Faheem Mitha
Guest





PostPosted: Sun Oct 30, 2005 9:57 pm    Post subject: Re: template instantiation syntax Reply with quote



On Sun, 30 Oct 2005 17:53:54 GMT, Faheem Mitha <faheem (AT) email (DOT) unc.edu> wrote:
Quote:
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 {
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
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.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.