default-value

C++11: template parameter redefines default argument

人走茶凉 提交于 2019-11-28 12:10:55
When compiling the following source code with gcc there are no errors / warnings: template< typename T = int > T func( ); template< typename T = int > T func( ); When I compile the same source code with clang++, I got the following error: redeftempparam.cc:2:24: error: template parameter redefines default argument template< typename T = int > T func( ); ^ redeftempparam.cc:1:24: note: previous default template argument defined here template< typename T = int > T func( ); ^ 1 error generated. Command to compile [clang++|g++] -Wall -Werror -std=c++11 redeftempparam.cc (Version information: gcc 4

What is the default value of a member in an array?

泄露秘密 提交于 2019-11-28 11:52:59
I instantiate an array like this: int array[] = new int[4]; What are the default values for those four members? Is it null, 0 or not exists? It's 0. It can't be null, as null isn't a valid int value. From section 7.6.10.4 of the C# 5 specification: All elements of the new array instance are initialized to their default values (§5.2). And from section 5.2: The default value of a variable depends on the type of the variable and is determined as follows: For a variable of a value-type, the default value is the same as the value computed by the value-type’s default constructor (§4.1.2). For a

C# Variable Initialization Question

喜欢而已 提交于 2019-11-28 09:53:37
Is there any difference on whether I initialize an integer variable like: int i = 0; int i; Does the compiler or CLR treat this as the same thing? IIRC, I think they're both treated as the same thing, but I can't seem to find the article. I looked at the IL (using ildasm) and its true that only the int set to 0 is really set to 0 in the constructor. public class Class1 { int setToZero = 0; int notSet; } Generates: .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { // Code size 15 (0xf) .maxstack 8 IL_0000: ldarg.0 IL_0001: ldc.i4.0 IL_0002: stfld int32

Is it possible to declare a public variable in vba and assign a default value?

五迷三道 提交于 2019-11-28 09:35:04
I want to do this but it won't compile: Public MyVariable as Integer = 123 What's the best way of achieving this? .NET has spoiled us :) Your declaration is not valid for VBA. Only constants can be given a value upon application load. You declare them like so: Public Const APOSTROPHE_KEYCODE = 222 Here's a sample declaration from one of my vba projects: If you're looking for something where you declare a public variable and then want to initialize its value, you need to create a Workbook_Open sub and do your initialization there. Example: Private Sub Workbook_Open() Dim iAnswer As Integer

How to set default value of TextBox empty string instead of null

不羁的心 提交于 2019-11-28 08:57:47
I may be out of date, but one principle I adhere to is avoid nulls as much as possible. However what I have found is that for a strongly typed view in which the user inputs the properties of an object I want to save, if some fields are not entered they are assigned as null. Then when you try to save the changes, the validation fails. So rather than set each property to an empty string, how can I automatically set each TextBox on a form to default to an empty string rather than a null? You could put the following attribute on your string-properties in your model: [DisplayFormat

Difference between mutation, rebinding, copying value, and assignment operator

我是研究僧i 提交于 2019-11-28 07:45:49
#!/usr/bin/env python3.2 def f1(a, l=[]): l.append(a) return(l) print(f1(1)) print(f1(1)) print(f1(1)) def f2(a, b=1): b = b + 1 return(a+b) print(f2(1)) print(f2(1)) print(f2(1)) In f1 the argument l has a default value assignment, and it is only evaluated once, so the three print output 1, 2, and 3. Why f2 doesn't do the similar? Conclusion: To make what I learned easier to navigate for future readers of this thread, I summarize as the following: I found this nice tutorial on the topic. I made some simple example programs to compare the difference between mutation , rebinding , copying value

Method parameter array default value [duplicate]

北城余情 提交于 2019-11-28 07:20:48
问题 This question already has an answer here: Passing an empty array as default value of an optional parameter [duplicate] 3 answers In c# it is possible to use default parameter values in a method, in example: public void SomeMethod(String someString = "string value") { Debug.WriteLine(someString); } But now I want to use an array as the parameter in the method, and set a default value for it. I was thinking it should look something like this: public void SomeMethod(String[] arrayString = {

How to set a default value in react-select

不打扰是莪最后的温柔 提交于 2019-11-28 07:14:34
i have an issue using react-select. I use redux form and i've made my react-select component compatible with redux form. Here is the code: const MySelect = props => ( <Select {...props} value={props.input.value} onChange={value => props.input.onChange(value)} onBlur={() => props.input.onBlur(props.input.value)} options={props.options} placeholder={props.placeholder} selectedValue={props.selectedValue} /> ); and here how i render it: <div className="select-box__container"> <Field id="side" name="side" component={SelectInput} options={sideOptions} clearable={false} placeholder="Select Side"

MySQL default date() + 14 days, for a column?

孤街醉人 提交于 2019-11-28 04:39:13
问题 I was wondering if the following is possible to do through MySQL or will it have to be done using PHP. Task - "Expiry Date" User enters product name User clicks submit form button Data is POST'ed and then sent to MySQL Expiry date = date now + 14 days What I am trying to achieve is a way for mysql to insert an "expiry_date" in a table column that will equal 14 days after the date the row was created in that table. e.g. product_name - foo entry_date - 2012-02-01 expiry_date - 2012-02-15 I have

How to set default values in Go structs

冷暖自知 提交于 2019-11-28 03:25:43
There are multiple answers/techniques to the below question: How to set default values to golang structs? How to initialize structs in golang I have a couple of answers but further discussion is required. vodolaz095 One possible idea is to write separate constructor function //Something is the structure we work with type Something struct { Text string DefaultText string } // NewSomething create new instance of Something func NewSomething(text string) Something { something := Something{} something.Text = text something.DefaultText = "default text" return something } Prateek Force a method to