Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > stl container as default arguments - how?

Reply
Thread Tools

stl container as default arguments - how?

 
 
FBergemann@web.de
Guest
Posts: n/a
 
      11-02-2006
Hi,

i wanted to merge two constructors

explicit Tokenizer (const string& token);
explicit Tokenizer (const string& token, const list<string>&
elements);

into one

explicit Tokenizer (const string& token, const list<string>&
elements = const list<string>& ());

But this doesn't compile.
What's the correct syntax?

- Thanks!

Frank

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      11-02-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Hi,
>
> i wanted to merge two constructors
>
> explicit Tokenizer (const string& token);
> explicit Tokenizer (const string& token, const list<string>&
> elements);
>
> into one
>
> explicit Tokenizer (const string& token, const list<string>&
> elements = const list<string>& ());
>
> But this doesn't compile.
> What's the correct syntax?


You can't default-initialize a reference.

explicit Tokenizer (const string& token,
const list<string>& elements = list<string> ());

Note that this will create a temporary empty list whenever the default
argument is used.

 
Reply With Quote
 
 
 
 
FBergemann@web.de
Guest
Posts: n/a
 
      11-03-2006

Rolf Magnus schrieb:
[...]
thanks for the hint - but you're right:

> Note that this will create a temporary empty list whenever the default
> argument is used.


that's a reason to hold on two constructors for it

Regards!

Frank

 
Reply With Quote
 
 
 
Reply

Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
function default arguments from other arguments tutmann C++ 4 10-17-2006 08:00 PM
container inside container in stl wolverine C++ 2 07-24-2006 03:08 PM
Copy elements from one STL container to another STL container Marko.Cain.23@gmail.com C++ 4 02-16-2006 05:03 PM
Difference between default arguments and keyword arguments Edward Diener Python 14 04-05-2004 11:26 PM
STL: container's values setup by another container Maitre Bart C++ 2 02-11-2004 12:11 AM



Advertisments