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
30
votes
7 answers

Getting Eclipse to open .html in text-editor by default?

Eclipse Juno keeps opening my HTML files in a embedded web-browser, rather than in an embedded syntax-highlighting editor. I have installed: Web Page Editor Eclipse Web Developer Tools PyDev for Eclipse Specifically see the screenshot of my…
25
votes
3 answers

Why C++ CLI has no default argument on managed types?

The following line has the error Default argument is not allowed. public ref class SPlayerObj{ private: void k(int s = 0){ //ERROR } } Why C++ has no default argument on managed types ? I would like to know if there is a way to fix this.
Mohsen Sarkar
  • 5,910
  • 7
  • 47
  • 86
21
votes
3 answers

Platform independent /dev/null in c++

Possible Duplicate: Implementing a no-op std::ostream Is there any stream equivalent of NULL in c++? I want to write a function that takes in a stream if the user wants to have the internal outputted to somewhere, but if not, the output goes into…
calccrypto
  • 8,583
  • 21
  • 68
  • 99
21
votes
4 answers

Technical reason for no default parameters in Java

I've been looking around to try to find what the reasoning is behind not including default parameters for functions in Java. I'm aware that it's possible to simulate the behavior, either with varargs or else by creating several overloaded functions…
Kricket
  • 4,049
  • 8
  • 33
  • 46
21
votes
7 answers

Default parameters: can only the last argument(s) be left?

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 last one as default eg.: foo(2); // a = 2 and b = 1…
UNKN57
  • 223
  • 2
  • 8
20
votes
2 answers

Dereferencing a function with default arguments - C++14 vs C++11

Following code can't be compiled with g++ version 5.4.0 with option -std=c++1y: void f(int=0) ; int main() { f(); // ok (*f)(2);// ok (*f)();// ok c++11; error with c++14: too few arguments to function return 0; } The function…
20
votes
2 answers

Evaluation order of function arguments and default arguments

I recently ran across the following situation: #include int *p = 0; int f() { p = new int(10); return 0; } void g(int x, int *y = p) { std::cout << y << std::endl; } int main() { g(f()); } This is quite subtle, since…
phlipsy
  • 2,899
  • 1
  • 21
  • 37
19
votes
7 answers

Fortran 2003 / 2008: Elegant default arguments?

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 awkward constructs like PROGRAM PDEFAULT CALL…
18
votes
2 answers

C#, default parameter value for an IntPtr

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 can do what I want?
Tom Davies
  • 2,386
  • 3
  • 27
  • 44
16
votes
1 answer

Why can't I have template and default arguments?

I changed a paremeter in a function to accept any kind of object using a template but I can't use it in conjunction with other default parameters, is there something I am missing? #include #include class MyClass { public: …
shuji
  • 7,369
  • 7
  • 34
  • 49
15
votes
4 answers

Can an unnamed parameter of function have a default value?

Is the following code legal in C++? void f(void* = 0) {} int main() { f(); } Which page of the C++ standard states that this usage is legal?
xmllmx
  • 39,765
  • 26
  • 162
  • 323
15
votes
2 answers

How should Scala default arguments to refer to a previous positional argument?

Scala-lang reference 5.5.1 and 6.6.1 gave me the impression that a default parameter would be able to refer to a previously evaluated one: class Test(val first: String, val second: String = first) but from experimenting it seems the only way to do…
13
votes
5 answers

Why doesn't C# allow a typeof as a default parameter?

class MyClass { public void MyMethod(Type targetType = typeof(MyClass)) { } } Isn't typeof(MyClass) a compile-time constant?
cazavientos
  • 141
  • 5
13
votes
3 answers

How to handle nested default parameters with object destructuring?

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 - Flat object destructuring with default…
13
votes
3 answers

How to pass a default parameter for std::shared_ptr

I have a function of type virtual void foo(bla, bla, bla, std::shared_ptr logger) = 0; And I want to pass a default parameter with NULL pointer, something like: virtual void foo(bla, bla, bla, std::shared_ptr
Eric Abramov
  • 462
  • 4
  • 19
1
2
3
24 25