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 ArticleBy: 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 ArticleBy: 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 ArticleBy: 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 ArticleBy: 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 ArticleBy: 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 ArticleBy: 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 ArticleBy: 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 ArticleBy: Alex
You can't. Default parameters must be compile-time constants, and deck is a variable.
View ArticleBy: 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