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

C# - default parameter values from previous parameter

namespace HelloConsole { public class BOX { double height, length, breadth; public BOX() { } // here, I wish to pass 'h' to remaining parameters if not passed // FOLLOWING Gives compilation…
sagarkothari
  • 24,520
  • 50
  • 165
  • 235
0
votes
2 answers

Scala default function literal parameter

In scala is it possible to provide a default value for a parameter that is a function? For example, in my code I have something like this. def noop(): Unit = {} def doSomethingGreat(succeed: Boolean)(f: => Unit)(default: => Unit = noop): Unit = { …
0
votes
1 answer

Scope of variables in Python methods with identical default parameters?

After a good bit of searching i couldn’t find any examples covering this. But i might not be using the correct terminology, since im confused about the situation, and what to even ask if that makes sense? So i feel like this is a duplicate…
0
votes
1 answer

Passing a function with default parameters

In Scala (v2.8.0, on SimplyScala.com), if I define a 2-ary function with a default parameter, why can't I pass it as a 1-ary function? This def bah(c:Char, i:Int = 0) = i List('a','b','c').map(bah) gives this error: type mismatch; found : (Char,…
leewz
  • 3,201
  • 1
  • 18
  • 38
0
votes
1 answer

Why does C# make the caller provide the actual parameter value for a method that has an optional parameter?

The last section of this blog explains the what: http://lostechies.com/jimmybogard/2010/05/18/caveats-of-c-4-0-optional-parameters/ But I am still wondering about the why. I recently came across the default parameter of Scala. In Scala it's the…
0
votes
2 answers

default value for functions in parameters in Scala

I was learning and experimenting with Scala. I wanted to implement a function with generic type, which takes a function as a parameter and provides a default implementation of that function.. Now when I try it without the generic type, it works…
Aditya Pawade
  • 866
  • 9
  • 19
0
votes
0 answers

Unnamed namespace and default function arguments

I was wondering, how I could set a const member variable of an unnamed namespace as a default function parameter where the function is declared in an named namespace. Well I guess this is hard to explain for me, here is an example of what I want to…
KO70
  • 189
  • 2
  • 15
0
votes
1 answer

Use derived class instance as default parameter value

I need a static method of my Base class to have a default parameter value of type Derived. Is there a way to implement this without use of overloading? (see here). class Base; class Derived; Derived make_derived(void); class Base { public: …
Daniel Jour
  • 15,896
  • 2
  • 36
  • 63
0
votes
1 answer

Python 2.7: Defining default parameters based on globals?

I'm writing a utility where I would like to have global variables that change the way a function operates. By default I'd like all the functions to follow one style, but in certain cases I'd also like the ability to force the way a function…
flakes
  • 21,558
  • 8
  • 41
  • 88
0
votes
0 answers

how could i distinguish default-parameter method in python

recently,i am learn python.i met a problem when i readed this book named The_Python_Tutorial.it's about how to distinguish the method with default parameter.i googled and read other books while i try to solve it,but i failed.if you can help…
Mark
  • 1
  • 2
0
votes
1 answer

Template class instantiation in default parameter not allowed in MSVC12?

I just extracted the following problem in our project. The following code just compiles fine with g++ #include class A {}; typedef std::vector vec_t; class bar { public: bar(vec_t) {}; }; class foo { public: foo(bar* a = new…
0
votes
1 answer

behavior of default parameters in python function declaration?

I got this question from the answer of this post. consider this code def test(a,dict={}): b=5 dict[a]=1 print dict print locals() test(1) test(2) The output is: {1: 1} {'a': 1, 'b': 5, 'dict': {1: 1}} {1: 1, 2: 1} {'a': 2,…
brain storm
  • 30,124
  • 69
  • 225
  • 393
0
votes
1 answer

Why local variable gets "remembered" in this case?

def word_to_syllable(w,li=[]): if not w: return li pattern = """ ######## """ pattern = re.sub("C","[^aeiou]",pattern) pattern = re.sub("V","[aeiou]",pattern) match = re.findall(pattern,w,re.VERBOSE)[0] …
0
votes
1 answer

Template function default parameter and type inference

C++ None of these template functions template void foo(T par = nullptr) {return;} //#1 template void foo(T par = std::nullptr_t(nullptr)) {return;} //#2 template void foo(T par = int(0)) {return;} //#3 allow…
0
votes
2 answers

Defining the default value for a ULONG& optional parameter as 0

The following function declaration: void Foo:DoSomething( ULONG &Count = 0) { .... } Results in the following compile time error error C2440: default argument cannot convert from 'int' to 'ULONG &' What is the correct way of creating the signature…
pondigi
  • 856
  • 2
  • 8
  • 14