STL Initialisation

Discussion in 'C Programming' started by dandeliontree.com, Apr 28, 2008.

  1. dandeliontree.com

    dandeliontree.com

    Joined:
    Apr 28, 2008
    Messages:
    1
    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::pair<int, Creator*> initMap[] = {
    // sig Id CTor
    // ------ -------------------------
    std::pair<int, Creator*>(1, new CreateOne()),
    std::pair<int, Creator*>(2, new CreateTwo()),
    std::pair<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::pair<int, Creator*> * How does it work?

    Cheers,
    DLT
    dandeliontree.com, Apr 28, 2008
    #1
    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. Adie
    Replies:
    5
    Views:
    322
  2. Wendy S
    Replies:
    0
    Views:
    948
    Wendy S
    Jun 28, 2003
  3. Xavier Tarrago
    Replies:
    0
    Views:
    1,435
    Xavier Tarrago
    Jun 30, 2003
  4. stixwix

    Runtime initialisation

    stixwix, Feb 16, 2006, in forum: Java
    Replies:
    3
    Views:
    345
    Mike Schilling
    Feb 17, 2006
  5. Tim Clacy
    Replies:
    8
    Views:
    393
    Tim Clacy
    May 30, 2006
Loading...

Share This Page