By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,442 Members | 1,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,442 IT Pros & Developers. It's quick & easy.

template instantiation syntax

P: n/a
Hi,

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

describing a generic factory class.

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

http://downloads.gamedev.net/feature...ory/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.
Oct 30 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sun, 30 Oct 2005 17:53:54 GMT, Faheem Mitha <fa****@email.unc.edu> wrote:
Hi,

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

describing a generic factory class.

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

http://downloads.gamedev.net/feature...ory/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.
Oct 30 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.