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
0
votes
2 answers

Derived class calling parent class's method that calls an overriden virtual method calls the wrong method

First of all, sorry for the confusing title. I have no idea how to word this properly. The problem is not really a problem, but rather something that I don't know how to implement. Here is the code: #include class Parent { public: …
0
votes
3 answers

Skiping parameters to retain defaults in JavaScript

The scenario is as follows: function: const fun = (a="keep this", b="change this")=>{return a + b}; How can I keep the first default parameter and override the second one? I have several functions that use many default parameters that are called in…
David Kamer
  • 2,677
  • 2
  • 19
  • 29
0
votes
1 answer

Getting a reference to an instance variable with a default parameter in Swift

So given the following code, how does one get a reference to a function that takes a parameter with a default value and invoke the reference with the default value? class Test { func doIt() { print("Done") } func doIt(_ adjective: String =…
nyteshade
  • 2,712
  • 1
  • 14
  • 9
0
votes
1 answer

Ghostscript mswinpr2 does not select default setting

I must provide a silent print of PDF to physical printer. I'm using ghostscript but I have a problem: the windows default printer settings are ignored by ghostscript. For example if I select color to b/w or paper tray in default printer settings…
Tobia
  • 9,165
  • 28
  • 114
  • 219
0
votes
1 answer

syntax support for es6 (default params) in visual studio 2015

I am trying to use the default parameters in the javascript function parameters var _BindAddNewPipelineButton = function(pipeId = undefined, enableEditMode = false) { Its not recognizing proper syntax highlighting and breaking my javascript…
0
votes
1 answer

Lexical declaration problems with default params

I'm having some problems when defining some functions after declaring a class. I've used default params before when declaring functions, but I don't know if I can use a function or class as default parameter too. My code is this const Matrix = class…
Fernando Carvajal
  • 1,869
  • 20
  • 19
0
votes
1 answer

python grammar specification : typedargslist

I was checking python grammar specification,and functions in python are defined like this using BNF. funcdef: 'def' NAME parameters ['->' test] ':' suite parameters: '(' [typedargslist] ')' typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])*…
0
votes
1 answer

Are there any ways around default parameters needing to be declared at compliation in python?

So I was working on a bit of code and found that when defining things recursively you can't have a method with a default variable based off of a passed in variable. A bit of surface level research shows that Python requires these to be declared at…
Ezra
  • 3
  • 2
0
votes
1 answer

Why can't i ignore a closure parameter with a default function in Swift?

I have a method with a closure as a parameter that defaults to a 'dummy' function if no closure is provided. However, whenever I try omitting the parameter with the default, the compiler throws the error: Missing argument for parameter…
Lennin
  • 481
  • 5
  • 11
0
votes
0 answers

Python: default parameter replaced by wrong side effect value

I am pretty new to python so it might simply be that I did not understand some parts of the language. Here is some code that I managed to make minimal for the sake of the example: class A(object): def __init__(self): self.m = 5 class…
Kiplaki
  • 171
  • 6
0
votes
3 answers

how to pass a value to its parameter (default parameters)

I'm really confused because I can't describe my question well, but I'm sure that many of you will understand me. #include using namespace std; void display(int n = 1, char c = '*'); int main() { display(); display(5); …
MiDo
  • 67
  • 1
  • 6
0
votes
1 answer

How to pass an Exception, with default "cause" as function parameter in Scala

I am writing a micro-service in Scala, and I am processing a response from a server, handling errors by throwing different exceptions. The error processing is basically the same for each error, log a warning message and throw an exception. The only…
0
votes
1 answer

C# default parameter by name is this possible?

May be this is a stupid question but: I wonder if there is something like default parameter but not by value - but by name. Example: I must use a parameter "IWebDriver driver" in a lot of my methods. And I know that always when I use it I will use…
Stanislava
  • 91
  • 2
  • 9
0
votes
1 answer

Default parameter value in this __init__() method's definition?

I am looking at some python code to control a camera and having some trouble understanding it due to being new at python. I see that the src parameter is set to 0. Does this mean that if a src is not given 0 will be used otherwise the given src…
Lightsout
  • 3,454
  • 2
  • 36
  • 65
0
votes
1 answer

Optional parameters in function

Is it possible to not define function parameters and use a default value in that case? For example. function nutrition_facts(calories = 0, fat = 0, carb = 0, protein = 0) { cal += calories; f += fat; carbohydrate += carb; p +=…
Roger
  • 83
  • 3
  • 9