Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old March 28th, 2006, 05:15 AM
vivekian
Guest
 
Posts: n/a
Default 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 ,

  #2  
Old March 28th, 2006, 07:35 AM
Asongala@gmail.com
Guest
 
Posts: n/a
Default Re: passing argument to user defined type

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

  #3  
Old March 28th, 2006, 10:35 AM
andy@servocomm.freeserve.co.uk
Guest
 
Posts: n/a
Default 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

  #4  
Old March 28th, 2006, 08:25 PM
Marcus Kwok
Guest
 
Posts: n/a
Default 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(PeerList(42));

--
Marcus Kwok
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.