passing argument to user defined type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vivekian

    #1

    passing argument to user defined type

    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 ,

  • Asongala@gmail.com

    #2
    Re: passing argument to user defined type

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

    Comment

    • andy@servocomm.freeserve.co.uk

      #3
      Re: passing argument to user defined type

      Asongala@gmail. com wrote:[color=blue]
      > std::list <PeerList> pl ;
      > PeerList p(int);
      > pl.push_back(p) ;[/color]

      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

      Comment

      • Marcus Kwok

        #4
        Re: passing argument to user defined type

        andy@servocomm. freeserve.co.uk wrote:[color=blue]
        > 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 );[/color]

        I would probably be explicit and do:

        pl.push_back(Pe erList(42));

        --
        Marcus Kwok

        Comment

        Working...