Quantcast
Channel: Comments on: 7.7 — Default parameters
Browsing latest articles
Browse All 48 View Live

By: Alex

I believe you are correct. This is generally avoided by putting your function prototypes in a header and #including that header wherever you need access to the function. That way you only have a single...

View Article



By: Peter Baum

1. Is there any good reason why C++ does not support more flexible default values such as 1 printValues(,,3) and 1 void printValue(int x=10, int y); ? 2. It seems strange that “Once declared, a default...

View Article

By: nascardriver

Hi Peter! 1. I don't think there is. The boost library has a feature to explicitly use a default parameter when calling a function. I like your first suggestions, but I don't like the second one. 2....

View Article

By: Peter Baum

Hi nascardriver, Regarding 2... if they had different default values maybe the compiler could point out the conflict.  That would take care of the redundancy too, because the programmer could use that...

View Article

By: Alex

This is a pretty common question. There's some conversation about this topic <a href="https://stackoverflow.com/questions/1123725/why-should-default-parameters-be-added-last-in-c-functions"...

View Article


By: nascardriver

@std::optional can be used, but you'd have to set the default value in the function body which isn't where default values should be located in my opinion. If there is a better way I'd love to know it....

View Article

By: Alex

I agree. I'm not aware of a way to solve this, but I'm also not that familiar with some of the C++17 stuff, so maybe someone who is knows of a good way to resolve.

View Article

By: ST.James

In the challenge section in lesson 6 (the blackjack game), we're almost sure that each time we call shuffleDeck, we will be passing in a deck of cards (&deck); how do we make "&deck" a default...

View Article


By: Alex

You can't. Default parameters must be compile-time constants, and deck is a variable.

View Article


By: magaji::hussaini

Hi alex I think a note should added that only copy initialisation work with default parameters because I got a compile time error when I tried uniform/direct initialisations. 12345 void printValues(int...

View Article
Browsing latest articles
Browse All 48 View Live




Latest Images