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

Template functions as default template parameters

My class declaration begins as follows: template< class P, class B, class comparePosition = compareHorizontal< P > > class BlahBlah { ... where compareHorizontal is a template function. When I attempt to compile, clang spits…
0
votes
2 answers

c++ float array as default parameter

I'm quite new to c++ and I don't manage to make this works. Sorry but i have always worked with languages that didn't helped me to think in terms of memory pointers ans so maybe this is a fooly question. I want to pass a float array as a default…
nkint
  • 11,513
  • 31
  • 103
  • 174
0
votes
1 answer

Python 3: Giving a command to set attribute of self in __init__ with need to use "self"?

I know the question header sounds weird, but since English is not my first language, I find it very hard to formalize. However, I might be able to explain it with bit more text. The problem is, that I'm trying to create a class called "Foo" for…
user1632861
0
votes
2 answers

C++ Creating an instance of a class?

Possible Duplicate: Default constructor with empty brackets Instantiate class with or without parentheses? Program: class Foo { public: Foo ( int bar = 1 ) { cout << "bar=" << bar; } }; int main() { cout << "0 -…
Kolyunya
  • 5,973
  • 7
  • 46
  • 81
0
votes
2 answers

Failure default param in UnitTests

In my project I have two files Products.h and .m. If I build project and run, I dont get any warnings & errors. But when I run tests. I catch an error on this piece of source code: NSArray* fetchItem(NSString* entity, NSSortDescriptor*…
Ilya Ilin
  • 2,283
  • 21
  • 27
-1
votes
1 answer

C# how to interpret this `this` in function definition?

I guess I never looked careful enough at the code I added before. Can someone help elaborate on the signature of this function? It is from .net 3.5 code, there is no default parameter support. But this this behaves just like default parameter. The…
Ben
  • 1,133
  • 1
  • 15
  • 30
-1
votes
1 answer

Workaround Mutable Default Arguments in Python

Going through the python documentation, I came across below. Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes. For…
Kraken
  • 23,393
  • 37
  • 102
  • 162
-1
votes
1 answer

Swift - Reference default comparison function as a function parameter

I'm trying to implement a convenience Collection.sorted(by: KeyPath) function. So far, it works if do func sorted(by keyPath: KeyPath) -> [Element] { return sorted { lhs, rhs return lhs[keyPath: keyPath] <…
Skwiggs
  • 1,348
  • 2
  • 17
  • 42
-1
votes
1 answer

Is hacking an app config value as a default parameter a code smell?

I'm trying to use App.config and Configuration Manager for the first time. I wanted to use some values in App.config as default parameters for some methods, but this results in an error (not a compile time constant): public void…
eriyg
  • 99
  • 1
  • 12
-1
votes
3 answers

Default Parameter Value for Function Type as Parameter Type in Swift 3

I want to pass a function to call inside the completion block if I need to, but I do not know how to set a default parameter for a function. func showAlert(controllerTitle: String, message: String, actionTitle: String, preferredStyle:…
-1
votes
3 answers

How would I use an asynchronous function as a default parameter for another function

I am trying to make a function that will call another function if the parameter doesn't exist. For example: function getAllFoo(){ // makes a request to an api and returns an array of all foos } function getNumFoo(foosArray = getAllFoo(), num =…
-1
votes
1 answer

Class template constructor default arguments

I am trying to make the constructor to set default values for template types as following: With this struct template template struct Pair This is my constructor: Pair(const Type1& t1 = Type1(), const Type2& t2 = Type2())…
rain_
  • 734
  • 1
  • 13
  • 24
-1
votes
1 answer

Set Default parameter in SSRS from a dataset

How can i set the default parameter in SSRS using a value from Dataset? I want the default parameter to be the previous month date that is selected from a table tblPeriod(per_id, lastDay) tblPeriod stores the months in a set of 20 year with last…
Navaneeth
  • 190
  • 1
  • 1
  • 16
-1
votes
1 answer

reassign default parameter on function call

I'm sure this has been asked hundred of times before, but curiously I can't find anything... I wonder how I can reassign a value to a default function parameter upon call specifically, omitting other parameters that stand to the left of it. This…
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
-1
votes
2 answers

Error CS0121 with double and int

I have an error: Error CS0121 The call is ambiguous between the following methods or properties: 'Program.calculateFee(double, int)' and 'Program.calculateFee(double)' DailyRate. here is my code: void run() { …
wouterrobot
  • 11
  • 1
  • 7
1 2 3
24
25