Questions tagged [default-arguments]

A default argument is a value passed to a certain parameter of a function if the user does not explicitly supply a value for that parameter.

A default argument is a value passed to a certain parameter of a function if the user does not explicitly supply a value for that parameter.

Some language extend this concept to other entities that have parameters. An example is C++, which has default template arguments, which is a value, type or template that is provided as an argument to a template parameter if the user does not explicitly provide an argument.

356 questions
0
votes
1 answer

call a class member to get default parameters for another member function of same class

I am trying to achieve to call a class member to get default parameters for another member function of same class. Here is what I am doing: class y { virtual vector getLabels(); } class x: public y { virtual vector getLabels(); …
Aman Deep Gautam
  • 8,091
  • 21
  • 74
  • 130
0
votes
1 answer

Optional Parameters in VS2010 templitized class function

I have an odd issue in MSVS 2010. I have a class with a function that is templitized and contains an parameter with a default value. In my header file: typedef unsinged int data32 class myClass { private: ... public: ... …
radensb
  • 664
  • 1
  • 7
  • 25
0
votes
2 answers

function overloading class design

My program has a Car and CarManager class that looks similar to the following: #include class Car { public: void Draw() { Draw(m_opacity); } void Draw(float opacity) { } private: float m_opacity; }; class…
user974967
  • 2,928
  • 10
  • 28
  • 45
0
votes
1 answer

Improve code readability without performance loss

We have several classes where a call to a member function may change state and sometimes not depending on a boolean with default value. A a; a.set( "foobar" ); assert( a.changed() == true ); versus A a; a.set( "foobar", false ); assert(…
math
  • 8,514
  • 10
  • 53
  • 61
0
votes
1 answer

Default parameter in python with objects

I know I can define default parameters in python, but can I do so with objects? For example, I'd like to work with a p.expect object: def exitDevice(ip, m='', sendExit=True): if sendExit: m.send('exit') print "left device", ip Is…
WildBill
  • 9,143
  • 15
  • 63
  • 87
0
votes
4 answers

"TypeError: CreateText() takes exactly 8 arguments (5 given)" with default arguments

def CreateText(win, text, x, y, size, font, color, style): txtObject = Text(Point(x,y), text) if size==None: txtObject.setSize(12) else: txtObject.setSize(size) if font==None: txtObject.setFace("courier") …
Eli Nahon
  • 29
  • 1
  • 6
0
votes
3 answers

Concatenation of strings in a default argument

This is a piece of my code... def contactMaster(data="",url= str(chosenMaster)+"todolist"): print "url: "+url It prints only "todolist" instead of "http://www.mysite.com/blah/1234/todolist" Why isn't it working??
spatara
  • 893
  • 4
  • 15
  • 28
-1
votes
1 answer

When using a function as a default argument, why is that function always called?

I want to have a function that I can call it with or without an argument, using another function to get the argument value in case it is missing. I already tried this: def GetValue(): ... def Process (value = GetValue): ... I tried to call the…
hirata1
  • 7
  • 1
-1
votes
2 answers

What's the best and safest way to dynamically create object of derived class passed as default function argument?

I have a classes class Base { public: virtual ~Base() {} virtual string returnString() = 0; }; class B : public A { public: string returnString() { return "string"; } } class C : public A { public: string returnString() { return…
Advent
  • 140
  • 15
-1
votes
1 answer

Fixing my point class with x and y ints, so it can pass just (x) instead of (x, y)

I have a task to solve. I was given a main and need to expand class to do programs in main and on the console to be printed (-1, 1). Given main: int main() { point a(2, 1), b(-3); a.move(b).print(); } and here is the code I wrote that is…
-1
votes
1 answer

Assigning lambda as default parameter to std::function type

For the following function: template decltype(auto) find_median( T begin, T end, bool sorted = false, const std::function comparison = [](auto a, auto b)->bool{return a < b;}) { assert(begin != nullptr); …
beep_boop
  • 819
  • 6
  • 15
-1
votes
2 answers

How to call two overloaded functions together if they have default parameters?

I have two functions with same name and default parameters but when I call them both together it gives me error. #include using namespace std; void add(int x=2,int y=4){ cout<
Annie
  • 9
  • 3
-1
votes
1 answer

Python tkinter Buttons are 'out of place' / not working properly

Hello avid python users... I was trying to create my first GUI writing a tic-tac-toe program but I ran into a problem regarding the 9 buttons on the grid. Here is part of the code that generates the buttons: button = 0 for x in range(3): …
-1
votes
1 answer

Default parameters order wrong result

I've seen an example giving wrong output when I try to run it. I don't understand why I get the wrong result while it is supplied in order. At the last call, I expect a=7, b=10. What's wrong? "use strict"; function f(a=1, b=2){ return(`a=${a},…
-1
votes
1 answer

How can I create default keyword arguments for a variadic function?

Suppose that we have a variadic function, such as the following: def oofay(*args, **kwargs): return "\u2609_\u2609" How can we set a default value for keyword argument "hamburg"? One solution is as follows: def oofay(*args, **kwargs): …
1 2 3
23
24