passing argument to user defined type

V

vivekian

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 ,
 
A

andy

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
 
M

Marcus Kwok

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));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top