default-parameters Questions

3

Solved

I'd like to use a default parameter value of IntPtr.Zero in a function that takes an IntPtr as an argument. This is not possible as IntPtr.Zero is not a compile time constant. Is there any way I c...
Prelude asked 21/10, 2012 at 15:58

24

Solved

Is there a way to specify default arguments to a function in C?
Jerricajerrie asked 24/9, 2009 at 14:38

3

I'm new to ES6 Javascript which means i'm exploring it. I like the arrow function and default parameter feature from ES6 which is mentioned in the below site. http://es6-features.org/#ExpressionB...
Chromophore asked 18/12, 2015 at 11:0

4

Solved

Please explain to me why the following piece of code complies and works perfectly. I am very confused. #include<iostream> template<class A = int, class B=double> class Base {}; templa...
Paddlefish asked 9/9, 2013 at 14:27

34

Solved

Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue: def foo(a=[]): a.append(5) return a Python novices would expect this function called with no ...

10

Solved

Sometimes it seems natural to have a default parameter which is an empty list. However, Python produces unexpected behavior in these situations. For example, consider this function: def my_func(wor...
Espinosa asked 14/12, 2008 at 11:23

7

Solved

I know it's possible to do something like : int foo(int a = 0, int b = 1) { return a + b; } and then use it without the default parameters eg.: foo(); // a = 0, b = 1 -> 1 or with the las...
Redeemer asked 3/10, 2016 at 18:34

27

Solved

I came across some Java code that had the following structure: public MyParameterizedFunction(String param1, int param2) { this(param1, param2, false); } public MyParameterizedFunction(String pa...
Limbic asked 15/6, 2009 at 18:4

7

Solved

In fortran, we can define default arguments. However, if an optional argument is not present, it can also not be set. When using arguments as keyword arguments with default values, this leads to aw...

3

Solved

For example, if I have the following data class: data class Data( val name: String = "", val number: Long = 0 ) And functions that can return null: fun newName(): String? {} fun newNumber():...
Puff asked 23/6, 2017 at 19:15

3

Solved

So I want to create a function that generates consecutive numbers from 'start' to 'end' as many as 'size'. For the iteration, it will be calculated inside the function. But I have problem to set de...
Mammillate asked 15/9, 2021 at 18:39

29

Solved

I would like a JavaScript function to have optional arguments which I set a default on, which get used if the value isn't defined (and ignored if the value is passed). In Ruby you can do it like th...

2

Solved

I want some of my function parameter to be optional, so I used default parameter as follow : fun defaultparameter(param1: String = "", param2: String = "", param3: Int = 0) thi...
Revitalize asked 8/6, 2021 at 10:59

2

Solved

The following code is rejected by mypy as expected: def foo(value: int) -> None: print(value, type(value)) foo(None) output: error: Argument 1 to "foo" has incompatible type "No...
Samantha asked 27/6, 2018 at 6:29

3

Solved

I am trying to figure out if it is possible to handle multiple levels of default parameters with destructuring. Since it is not easy to explain with words, here is a step-by-step example... 1 - ...

2

Solved

Assuming a kotlin function like this: fun f(p1: T1? = null, p2: T2? = null, ..., pN: TN? = null) { // ... } Can the above function's implementation distinguish between the following two calls, ...
Operand asked 12/5, 2020 at 20:51

4

Solved

Let's suppose we have a function like this: def myFunction(arg1='a default value'): pass We can use introspection to find out the names of the arguments that myFunction() takes using myFunction...
Emmettemmey asked 1/2, 2011 at 7:28

3

I have a function of type virtual void foo(bla, bla, bla, std::shared_ptr<LoggerInterface> logger) = 0; And I want to pass a default parameter with NULL pointer, something like: virtual v...
Nuptial asked 29/12, 2016 at 14:41

3

I need to pass a nullable parameter to a function that only accepts non nullable objects, but has a default value defined. Currently I'm using a let: fun myFun(a:String = "qqq"): Whatever {...} ...
Harlandharle asked 2/8, 2019 at 11:37

2

While debugging someone's nasty macro-generated code, I saw that MSVC++ alone was not happy with something akin to the following function template declaration: template <typename ...Vs, typenam...

9

Solved

I had a very difficult time with understanding the root cause of a problem in an algorithm. Then, by simplifying the functions step by step I found out that evaluation of default arguments in...
Zig asked 30/10, 2009 at 17:16

5

Solved

class MyClass { public void MyMethod(Type targetType = typeof(MyClass)) { } } Isn't typeof(MyClass) a compile-time constant?
Bouchier asked 20/1, 2012 at 9:48

3

Solved

My Javascript function leads my console to return me : TypeError: style is null Here the snippet: let style = { one: 1, two: 2, three: 3 } function styling(style = style, ...ru...
Virgate asked 2/6, 2019 at 18:15

5

Solved

While going through features of JavaScript, I used default arguments and spread syntax in same function. let whatIsThis = (a, b = 2, ...c) => { console.log("a = " + a, "b = " + b,"c = " + c) }...
Gleesome asked 22/8, 2018 at 8:44

2

Solved

Here is a function declaration with default arguments: void func(int a = 1,int b = 1,...,int x = 1) How can avoid calling func(1,1,...,2) when I only want to set the x parameter and for th...
Obliquity asked 8/8, 2018 at 10:11

© 2022 - 2024 — McMap. All rights reserved.