473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

stl container as default arguments - how?

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
2 1799
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved...
14
by: Edward Diener | last post by:
In the tutorial on functions there are sections on default arguments and keyword arguments, yet I don't see the syntactic difference between them. For default arguments the tutorial shows: def...
41
by: AngleWyrm | last post by:
I have created a new container class, called the hat. It provides random selection of user objects, both with and without replacement, with non-uniform probabilities. Uniform probabilities are a...
1
by: Aaron Walker | last post by:
Hey folks, I've got some code for an options class that stores user run time options (as static members) so that they are availably any time an instance is created; currently the code has a...
3
by: Peteris Krumins | last post by:
Hello! I would like to ask how to search for a container element which matches some criteria. Here is what I mean. Suppose I have a structure: struct my_struct { my_struct(const std::string...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
9
by: horizon5 | last post by:
Hi, my collegues and I recently held a coding style review. All of the code we produced is used in house on a commerical project. One of the minor issues I raised was the common idiom of...
2
by: babaco | last post by:
Hi, I've come upon a situation where I don't understand what's happening. Basically, I'm implementing a kind of 'chain of responsibility' using some covariant types: #include <iostream>...
5
by: bambam | last post by:
I wish to create a generic container object, devlist, such that devlist.method(arguments) runs as for each dev in devlist.pool: dev.method(arguments) and
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.