default-value

Not possible: this pointer as a default argument. Why?

瘦欲@ 提交于 2019-11-29 07:11:32
The following code won't compile. Why? class A { int j; void f( int i = this->j ); } Edit, for clarity. This is what I was trying to do, using less lines of code... class A { void f( int i ){}; void f( ); int j; }; void A::f() { f( j ); } Eric Default argument values are bound at compile time. "this" is only defined at run time, so can't be used. See here for a fuller explanation: Must default function parameters be constant in C++? Others have already commented on the reason this doesn't work. From one of the comments: "...The expression can combine functions that are visible in the current

Django: How to set initial values for a field in an inline model formset?

偶尔善良 提交于 2019-11-29 07:09:01
I have what I think should be a simple problem. I have an inline model formset, and I'd like to make a select field have a default selected value of the currently logged in user. In the view, I'm using Django's Authentication middleware, so getting the user is a simple matter of accessing request.user . What I haven't been able to figure out, though, is how to set that user as the default selected value in a select box (ModelChoiceField) containing a list of users. Can anyone help me with this? I'm not sure how to handle this in inline formsets, but the following approach will work for normal

Best practice for setting the default value of a parameter that's supposed to be a list in Python?

删除回忆录丶 提交于 2019-11-29 02:02:29
问题 I have a Python function that takes a list as a parameter. If I set the parameter's default value to an empty list like this: def func(items=[]): print items Pylint would tell me "Dangerous default value [] as argument". So I was wondering what is the best practice here? 回答1: Use None as a default value: def func(items=None): if items is None: items = [] print items The problem with a mutable default argument is that it will be shared between all invocations of the function -- see the

Python: list() as default value for dictionary

我的梦境 提交于 2019-11-29 01:11:15
I have Python code that looks like: if key in dict: dict[key].append(some_value) else: dict[key] = [some_value] but I figure there should be some method to get around this 'if' statement. I tried dict.setdefault(key, []) dict[key].append(some_value) and dict[key] = dict.get(key, []).append(some_value) but both complain about "TypeError: unhashable type: 'list'". Any recommendations? Thanks! The best method is to use collections.defaultdict with a list default: from collections import defaultdict dct = defaultdict(list) Then just use: dct[key].append(some_value) and the dictionary will create a

<select> dropdown default value

我只是一个虾纸丫 提交于 2019-11-29 00:16:49
I have this code: if(isset($_POST['search'])) { $res1=mysql_query("SELECT * FROM aircraft where acode = '$_POST[ac]'") or die(mysql_error()); while($row=mysql_fetch_array($res1)) { $airc=$row['acode']; $amode=$row['amodel']; $stat=$row['status']; $rem=$row['remarks']; echo "<center><table><form name=\"frmMain\" method=\"post\"> <tr><td><font face=consolas><b>Aircraft Code:</b></font></td><td><input type=text name=arc value='$airc' readonly=readonly></td></tr> <tr><td><font face=consolas><b>Aircraft Model:*</b></font></td><td><input type=text name=am value='$amode'></td></tr> <tr><td><font face

attr('defaultValue') is returning undefined using jQuery 1.6.3

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 23:37:42
I have a simple script in jQuery that works perfectly with jQuery 1.5.2 as you can see in this jsFiddle . What is supposed to happen is that when you bring focus to the text field, the default value is removed. And when if you leave the field blank, the original default value is put back in place. http://jsfiddle.net/kHBsD/ However, the same exact code, where only jQuery 1.6.3 is used instead, is not working. (Not working means that the default value remains in the text box until you manually delete it as you can see in this jsFiddle . http://jsfiddle.net/kHBsD/1/ There are no script errors in

mysql set field default value to other column

99封情书 提交于 2019-11-28 22:51:01
How to set default value for a field to other column in Mysql I have done it oracle with virtual field but I do not know how to do it in Mysql this is my table: create table TSM_TRANSACTION_TBL ( TRANS_ID INT primary key auto_increment, LOCATION_ID INT, TRANS_DATE DATE, RESOURCE_ID INT, TS_ID INT, MAX_VALUE INT, BOOKED_UNITS INT default 0, REMAINING INT default MAX_VALUE - BOOKED_UNITS, BOOKED INT not null, USER_ID INT, TRANS_TIME TIMESTAMP ) eggyal As documented under Data Type Default Values : The DEFAULT value clause in a data type specification indicates a default value for a column. With

Enum variable default value?

匆匆过客 提交于 2019-11-28 21:00:38
The question is simple: #include <iostream> enum SomeEnum { EValue1 = 1, EValue2 = 4 }; int main() { SomeEnum enummy; std::cout << (int)enummy; } What will be the output? Note: This is not an interview, this is code inherited by me from previous developers. Streaming operator here is just for example, actual inherited code doesn't have it. The program has Undefined Behavior . The value of enummy is indeterminate. Conceptually there is no difference between your code and the following code: int main() { int i; //indeterminate value std::cout << i; //undefined behavior }; If you had defined your

What does 'value initializing' something mean? [duplicate]

大城市里の小女人 提交于 2019-11-28 18:23:06
Possible Duplicate: What do the following phrases mean in C++: zero-, default- and value-initialization? If I have a class for example: class Info { int x; int y; }; which I used to created an object, Info *p = new Info(); Does the brackets beside Info mean i'm value initializing it? How does it different from this, Info *p = new Info; ? I know there is a question which differentiate between different meanings in new and old C++ language but I want to know the semantic difference between default and value initialization e.g. Does value initialization means initializing something to zero? A

C++ default initialization and value initialization: which is which, which is called when and how to reliably initialize a template-type member

社会主义新天地 提交于 2019-11-28 18:20:42
My question somewhat overlaps with this and several other similar ones. Those have some great answers, but I've read them and I'm still confused, so please don't consider this question a duplicate. So, I have the following code: class A { public: int _a; } void main() { A inst1; A* inst2 = new A; A* inst3 = new A(); } _a is left uninitialized in inst1 and inst2 and is initialized to 0 in inst3 . Which initialization is called which, and why does the code work as it does? Please take into I account I don't have a C++ 03 standard at hand, but I have the last C++ 11 draft (I'm programming by '03