passing argument to user defined type

Discussion in 'C++' started by vivekian, Mar 28, 2006.

  1. vivekian

    vivekian Guest

    Hi,

    trying to compile the following piece of code

    class PeerList
    {
    public :
    ....
    PeerList ( int noPieces )
    {
    // using noPieces to dynamically allocate memory for an
    array.
    }
    ~PeerList ()
    {
    ....
    }
    };

    Now trying to make a list of objects of type PeerList so trying the
    following :

    std::list <PeerList> pl ;

    But , how is the argument -- 'int noPieces' to be passed to this
    declaration ?

    thanks in advance ,
     
    vivekian, Mar 28, 2006
    #1
    1. Advertising

  2. vivekian

    Guest

    std::list <PeerList> pl ;
    PeerList p(int);
    pl.push_back(p);
     
    , Mar 28, 2006
    #2
    1. Advertising

  3. vivekian

    Guest

    wrote:
    > std::list <PeerList> pl ;
    > PeerList p(int);
    > pl.push_back(p);


    Or even :

    std::list <PeerList> pl ;
    PeerList p(1); // note Now this isnt a function definition!
    pl.push_back(p);

    //use Peerlist implicit int ctor
    pl.push_back(42);

    cheers
    Andy Little
     
    , Mar 28, 2006
    #3
  4. vivekian

    Marcus Kwok Guest

    wrote:
    > Or even :
    >
    > std::list <PeerList> pl ;
    > PeerList p(1); // note Now this isnt a function definition!
    > pl.push_back(p);
    >
    > //use Peerlist implicit int ctor
    > pl.push_back(42);


    I would probably be explicit and do:

    pl.push_back(PeerList(42));

    --
    Marcus Kwok
     
    Marcus Kwok, Mar 28, 2006
    #4
    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. Oodini
    Replies:
    1
    Views:
    1,842
    Keith Thompson
    Sep 27, 2005
  2. vivekian
    Replies:
    1
    Views:
    280
    Howard
    Mar 28, 2006
  3. Replies:
    2
    Views:
    438
  4. Replies:
    1
    Views:
    472
    Sylvester Hesp
    May 16, 2007
  5. Ryan Dupuis
    Replies:
    8
    Views:
    1,427
    Eric Sosman
    Oct 2, 2013
Loading...

Share This Page