Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > STL Initialisation

Reply
Thread Tools

STL Initialisation

 
 
dandeliontree.com dandeliontree.com is offline
Junior Member
Join Date: Apr 2008
Posts: 1
 
      04-28-2008
Hi Folks,
Newly back to c++ after about 6 years so I am extremely rusty. I managed to get the following code to work.

std:air<int, Creator*> initMap[] = {
// sig Id CTor
// ------ -------------------------
std:air<int, Creator*>(1, new CreateOne()),
std:air<int, Creator*>(2, new CreateTwo()),
std:air<int, Creator*>(3, new CreateThree())
};

template<typename T, std::size_t z> std::size_t size(T const (&a)[z]) {
return z;
}

FactoryInstance::FactoryInstance()
: sig2Hdlr(std::map<int, Creator*>(initStdMap,initStdMap+size(initStdMap))) ,
FactoryBaseClass(&sig2Hdlr)
{
}


Could someone please help me unnderstand this by explaining the following:

template<typename T, std::size_t z> std::size_t size(T const (&a)[z]) {
return z;
}

where the function template is instantiated with size(initStdMap) //where the type of initStdMap is std:air<int, Creator*> * How does it work?

Cheers,
DLT
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialisation of reference vs. initialisation of reference member Tim Clacy C++ 8 05-30-2006 06:14 PM
Runtime initialisation stixwix Java 3 02-17-2006 12:31 AM
class initialisation vallidation Adie ASP .Net 5 01-26-2004 11:49 PM
Re: [Struts] Init formbean value before Initialisation? Xavier Tarrago Java 0 06-30-2003 09:08 AM
Re: [Struts] Init formbean value before Initialisation? Wendy S Java 0 06-28-2003 01:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57