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
1 answer

Are Immutable named parameters (with defaults) possible in Typescript (compile time)?

The following example (which unfortunately doesn't work) should illustrate this question: function test({ name = 'Bob', age = 18 }: { readonly name?: string, readonly age?: number }) { // this should result in an error (but doesn't): name =…
0
votes
2 answers

Printing Return Value of Function having Mutable Default Argument

After reading this thread, I also tried to get my hands dirty with default arguments. So, following is the same function having the mutable default argument:- def foo(x = []): x.append(1) return x As defined in the docs, the default value…
Perspicacious
  • 594
  • 3
  • 17
0
votes
1 answer

How to define a default parameter of Vector2f ? [SFML]

I have some function func in a class Class: void func(int arg1, int arg2, Vector2f vec = Vector2f(0,0)){}; And I get a build error: error C2572: 'Classs::func': redefinition of default argument: parameter 1 I tried many different synataxes but…
user12326560
0
votes
0 answers

Not All Default Parameters Are Rendering

Can anyone tell me why one default parameter renders the default value while the other doesn't? Take this Nav component and its' props being passed. The heading prop renders however the props inside of navItems array does not. It will console log as…
Eric Nguyen
  • 926
  • 3
  • 15
  • 37
0
votes
2 answers

Setting Default Parameters With Nested Array

In my React project, I'm passing in an array of objects and wondering how I can set default parameter for the nested array. I've already set it on the main array const Nav = ({ navItems = [] }) but couldn't figure out how to set for nested array.…
Eric Nguyen
  • 926
  • 3
  • 15
  • 37
0
votes
0 answers

Is there a way to get a compile time constant CulutureInfo?

I have a method that is used to format some value with a given format string and an IFormatProvider. The signature is: public static string FormatParameter(object parameterValue, string format, IFormatProvider formatProvider) I want that the…
Ackdari
  • 3,222
  • 1
  • 16
  • 33
0
votes
2 answers

QuickSort infinite loop if I declare param defaults inside function using pre-2015 method, but works fine if I use ES2015 default param values

I have been trying to implement a quickSort function and have everything working. But there is one peculiarity that I cannot wrap my head around or understand why. In this first block of code, you will see that I have declared some default param…
0
votes
0 answers

How to use default parameters in a function without following the order at which parameters are declared in it

function Person(fname = 'First Name', lname = 'Last Name', age = 'Age') { this.fname = fname; this.lname = lname; this.age = age; } let person1 = new Person('husain', undefined, 1998); console.log('person1: ', person1); // output:…
Husain
  • 13
  • 1
  • 6
0
votes
1 answer

Specify the default value for the parameterful property in C#

How can I specify the default value for the parameterful property in C#? While exploring the C# I come across the following excerpt in the CLR via C# book: You can specify default values for the parameters of methods, constructor methods, and …
qqqqqqq
  • 1,831
  • 1
  • 18
  • 48
0
votes
0 answers

Aggregate with in-class initialization - as default argument

The following code does not compile (GCC, clang): struct outer { struct inner { int i = 1; int j = 2; }; void foo (const inner& param = inner{}) const {} }; int main() { outer{}.foo(); } However,…
Igor R.
  • 14,716
  • 2
  • 49
  • 83
0
votes
1 answer

How do I declare a default Tuple function parameter in a Scala?

I'd like to declare a function that receives a string and a Tuple2 with first value as boolean and second value as any type. The tuple2 should have a default value in case its not delivered to the function I tried the following code to set the…
PloniStacker
  • 574
  • 4
  • 23
0
votes
1 answer

The Default Parameter Set isn't is running through the if Statement

When I run this function without specifying the Count Parameter, it asks for the Source, which is expected, then doesn't return the information that the Count switch should return, but if I specify the Count Switch it returns the information I…
Nick Pope
  • 37
  • 1
  • 1
  • 5
0
votes
1 answer

What is the preferable way of initializing default arguments of a constructor?

I have seen following two ways of default initializing the arguments in constructors(which is also applicable in normal free functions too). #include using UserDefinedType = std::string; class MyClass { UserDefinedType…
UserUsing
  • 678
  • 1
  • 5
  • 16
0
votes
1 answer

How to pass null to SQL Server stored procedure param with NON-NULL default value

I have a SQL Server stored procedure inside a multi-tenant DB. It is used by all clients, but since I don't update them all at the same time I needed to provide default parameter values so clients wouldn't throw an error if they didn't pass in the…
Terry
  • 2,148
  • 2
  • 32
  • 53
0
votes
1 answer

Use a variable for named parameter in kotlin

I have a function defined as follows: getTypeB(id: String, valA1: TypeA = defaultA1 valA2: TypeA = defaultA2, valA3: TypeA = defaultA3 ) : TypeB {} I know using named arguments I can call the above function with only…