By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,233 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,233 IT Pros & Developers. It's quick & easy.

stl container as default arguments - how?

P: n/a
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

Nov 2 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
FB********@web.de 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.

Nov 2 '06 #2

P: n/a

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

Nov 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.