•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,634 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,232 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 137 | Replies: 2
![]() |
•
•
Join Date: Jan 2008
Location: USA East Cost
Posts: 389
Reputation:
Rep Power: 1
Solved Threads: 37
Is it bad to make a reference parameter optional by giving it a default value? Like here:
Here, the caller of the function may pass an optional std::string that will be filled with an error message if there is one. Is this considered "ok", both as far as being safe, good code and having good style?
int Parse(std::string filename, std::string& error = (std::string)"");
Here, the caller of the function may pass an optional std::string that will be filled with an error message if there is one. Is this considered "ok", both as far as being safe, good code and having good style?
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
It's legal construct (better use more accurate std::string(""), avoid old C style casts).
I don't like this style (tastes differ). It's an ineffective code (string constructor works on every call for default argument). It's some confusing code (pass by reference means inout parameter as ususlly).
In that case I prefer
I don't like this style (tastes differ). It's an ineffective code (string constructor works on every call for default argument). It's some confusing code (pass by reference means inout parameter as ususlly).
In that case I prefer
const char* msg = 0 - programmer's intentions are more evident... ![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C++ Forum
- Previous Thread: what does this mean?
- Next Thread: Trouble with vector of pointers



Linear Mode