Questions tagged [default-parameters]

A default parameter is a function or method parameter that has a default value provided to it. If the user does not supply a value for this parameter, the default value will be used. If the user does supply a value for the default parameter, the user supplied value is used.

A default parameter is a function or method parameter that has a default value provided to it. If the user does not supply a value for this parameter, the default value will be used. If the user does supply a value for the default parameter, the user supplied value is used.

366 questions
-1
votes
2 answers

C++ default constructors and default parameters

If I have a class containing: foo(); //sets baz to 10 foo(int bar = 0); //sets baz to bar int baz; Will the 'default' constructor ever be used? e.g. will: foo qux; default to baz = 0 or 10? Any difference for: foo * quux = new foo;
Flexo1515
  • 1,007
  • 1
  • 10
  • 27
-2
votes
1 answer

Why do Python iterable and non-iterable keyword argument types behave differently with multiple function calls?

I was reading this very informative question and answer and learned about this behavior for the first time: calling def foo(l=[]): l.append(1) print(l) foo() foo() foo([]) foo() prints [1] [1,1] [1] [1,1,1] I thought that was neat and…
-2
votes
1 answer

How to pass a string as default argument in C++

How can I properly pass a const string, for example: "Hello" as a default parameter to a constructor without getting any warnings and errors? In other words how can I preserve memory for them before the function is called?
Friendly Fella
  • 75
  • 1
  • 2
  • 10
-3
votes
2 answers

Why doesn't function overloading work when default parameters are specified?

When default parameters are not specified, function overloading works. But, why doesn't function overloading work when default parameters are specified? This program takes two integers and compares them to find the larger of the two. Then, it…
-3
votes
1 answer

When the function runs multiple times, the list is nested in the default parameter, but the integer is not

The list, x, isn't initialized to the parameter default value each time the function is operated, but remains in the previous state and adds a new value. That's how the function was executed 5 times, so it became [7, 7, 7, 7, 7]. However, the…
J. SungHoon
  • 201
  • 1
  • 5
1 2 3
24
25