Any Idea why this error is coming up at compile time?
ComplexNumber.cpp:21: error: default argument given for parameter 1 of ‘void ComplexNumber::print(std::ostream&) const’
ComplexNumber.h:17: error: after previous specification in ‘void ComplexNumber::print(std::ostream&) const’
Here is my code at those certain areas:
ComplexNumber.cpp
21 void ComplexNumber::print(ostream & out = cout) const {
ComplexNumber.h
17 void print(ostream & out = cout) const;
Generally no, but in gcc You may make the last parameter of funcA() optional with a macro.
Which is the correct condition for the default arguments? Explanation: The default arguments must be declared at last in the argument list. This is to ensure that the arguments doesn't create ambiguity.
In computer programming, a default argument is an argument to a function that a programmer is not required to specify. In most programming languages, functions may take one or more arguments. Usually, each argument must be specified in full (this is the case in the C programming language).
No you cannot overload functions on basis of value of the argument being passed, So overloading on the basis of value of default argument is not allowed either. You can only overload functions only on the basis of: Type of arguments. Number of arguments.
You should only specify the default parameter in the function declaration, i.e. in the header. You implementation should look something like this:
void ComplexNumber::print(ostream & out) const { ..... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With