473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

template instantiation syntax

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
1 1251
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: zhou | last post by:
Hi there, We have a compiler specific issue which requires us to force template instantiation. This works fine. The problem comes when I try using std:find() on vector. Since vector has no member...
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
3
by: Patrick Guio | last post by:
Hi, I have trouble to compile the following piece of code with g++3.4 but not with earlier version // Foo.h template<typename T> class Foo { public:
7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
3
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a...
2
by: Boni | last post by:
Dear all, ist it possible to have a template class or func as friend of other class: Folowing returns syntax errors template< typename T> class test{}; template< typename T> int func (Ta); ...
2
by: Andy Champ | last post by:
We have a class with something that, simplified, looks like this: template <typename Tclass foo { T beyondAllReaching; // In VC2005, this works OK template <typename Ufriend void...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.