default-parameters

Why does 'msg * alarm' disappear after a while?

∥☆過路亽.° 提交于 2021-02-07 10:48:12
问题 I have a small powershell script which allows me to quickly set an alarm for myself. It basically just waits a specified number of minutes and then calls msg * alarm! This works well - a message box pops up. The only problem is it disappears after a while - so if I'm not at my desk, I'll miss the message box. According to the documentation, found here, this is the behaviour when I don't specify a time value. /time: seconds : Specifies the amount of time the message you sent is displayed on

Scala extra no-arg constructor plus default constructor parameters

拜拜、爱过 提交于 2021-02-07 01:57:30
问题 I am using the Scala 2.8 default parameters on a constructor, and for Java compatibility reasons, I wanted a no-arg constructor that uses the default parameters. This doesn't work for very sensible reasons: class MyClass(field1: String = "foo", field2: String = "bar") { def this() = { this() // <-- Does not compile, but how do I not duplicate the defaults? } } I am wondering if there is anything that I am missing. Any thoughts that don't require duplicating the parameter defaults? Thanks! 回答1

Scala extra no-arg constructor plus default constructor parameters

烈酒焚心 提交于 2021-02-07 01:53:38
问题 I am using the Scala 2.8 default parameters on a constructor, and for Java compatibility reasons, I wanted a no-arg constructor that uses the default parameters. This doesn't work for very sensible reasons: class MyClass(field1: String = "foo", field2: String = "bar") { def this() = { this() // <-- Does not compile, but how do I not duplicate the defaults? } } I am wondering if there is anything that I am missing. Any thoughts that don't require duplicating the parameter defaults? Thanks! 回答1

Scala extra no-arg constructor plus default constructor parameters

会有一股神秘感。 提交于 2021-02-07 01:51:14
问题 I am using the Scala 2.8 default parameters on a constructor, and for Java compatibility reasons, I wanted a no-arg constructor that uses the default parameters. This doesn't work for very sensible reasons: class MyClass(field1: String = "foo", field2: String = "bar") { def this() = { this() // <-- Does not compile, but how do I not duplicate the defaults? } } I am wondering if there is anything that I am missing. Any thoughts that don't require duplicating the parameter defaults? Thanks! 回答1

Scala extra no-arg constructor plus default constructor parameters

十年热恋 提交于 2021-02-07 01:50:14
问题 I am using the Scala 2.8 default parameters on a constructor, and for Java compatibility reasons, I wanted a no-arg constructor that uses the default parameters. This doesn't work for very sensible reasons: class MyClass(field1: String = "foo", field2: String = "bar") { def this() = { this() // <-- Does not compile, but how do I not duplicate the defaults? } } I am wondering if there is anything that I am missing. Any thoughts that don't require duplicating the parameter defaults? Thanks! 回答1

Evaluation order of function arguments and default arguments

北慕城南 提交于 2021-02-04 21:58:29
问题 I recently ran across the following situation: #include <iostream> 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 you usually don't expect the default arguments to change during their evaluation for the function call. I had to take a look at the assembly to spot this error. Now my question is: Is this really undefined behavior, since there aren't any guarantees concerning the

Rationale behind constraining default parameters as compile-time constants

╄→尐↘猪︶ㄣ 提交于 2021-01-28 21:02:49
问题 I am wondering why this would not compile: public static void SomeFunction(Guid someGuid = Guid.NewGuid()) { // Do stuff } with the message "Default parameter value for 'someGuid' must be a compile-time constant" while the overloaded version would compile: public static void SomeFunction() { SomeFunction(Guid.NewGuid()); } public static void SomeFunction(Guid someGuid) { // Do stuff } In other words, why doesn't the compiler translate the first situation in the second? What lies behind this

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

假如想象 提交于 2021-01-13 07:57:53
问题 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 default -> 3 But my question is : Is it possible to use the default value for the first argument (a) and give the value of the second (b) My first thought was doing it like ( which doesn't work! ): foo(,2); // a = 0 default and b = 2 Does a syntax for this

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

别来无恙 提交于 2021-01-13 07:56:06
问题 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 default -> 3 But my question is : Is it possible to use the default value for the first argument (a) and give the value of the second (b) My first thought was doing it like ( which doesn't work! ): foo(,2); // a = 0 default and b = 2 Does a syntax for this

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

牧云@^-^@ 提交于 2021-01-13 07:55:35
问题 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 default -> 3 But my question is : Is it possible to use the default value for the first argument (a) and give the value of the second (b) My first thought was doing it like ( which doesn't work! ): foo(,2); // a = 0 default and b = 2 Does a syntax for this