default

How to use a member variable as a default argument in C++?

 ̄綄美尐妖づ 提交于 2019-11-28 22:38:14
I want to make an argument for one of the member functions optional. When no argument is provided, it would use an member variable. However, when I tried to compile it it shows " error: invalid use of non-static data member 'Object::initPos' " Just to isolate the problem, I tried defaulting an int type and it compiled fine. I wonder what is the problem with my code and how I could use a member function as default value. Thank you for your help! Object.h class Object { public: ... void MoveTo(double speed, Point position); protected: Point initPos; Point currPos; }; Object.c void Object::MoveTo

Define Default Activity (when app starts) programmatically

大兔子大兔子 提交于 2019-11-28 21:58:38
My application is composed by a few activity. Activity A is my main menu with some icons. This Activity can launch depending on which icon you press: Activity B,C,D,E or F. That's fine and really easy, Activity A is the default one. Now, I made an option in preference that allow users to start their favourite activity. Some users will in fact prefer to get directly Activity B for instance. The only way I found a solution was to do this in Activity A This solution is very ugly because Activity A will always launch and close automatically: public void onCreate(Bundle savedInstanceState) { super

How to translate “default(SomeType)” from C# to CIL?

可紊 提交于 2019-11-28 21:32:42
I'm currently working on a problem that involves System.Reflection.Emit code generation. I'm trying to figure out what CIL to emit in places where I would use default(SomeType) in C#. I've run a few basic experiments from Visual Studio 11 Beta. JustDecompile shows me the following CIL output for default(bool) , default(string) , and default(int? : .locals init ( [0] bool V_0, [1] string V_1, [2] valuetype [mscorlib]System.Nullable`1<int32> V_2 ) // bool b = default(bool); ldc.i4.0 stloc.0 // string s = default(string); ldnull stloc.1 // int? ni = default(int?); ldloca.s V_2 initobj valuetype

Java Map implementation that returns a default value instead of null

江枫思渺然 提交于 2019-11-28 20:07:38
I have a Map<String, List<String>> in my code, where I'd avoid potential null pointers if the map's #get() method returned an empty list instead of null. Is there anything like this in the java API? Should I just extend HashMap ? Stephen C @Jon's answer is a good way to do what you are asking directly. But is strikes me that what you might be trying to implement is a "multimap"; i.e. a mapping from a key to a collection of values. If that is the case, then you should also look at the multimap classes in Guava or Apache commons collections. Look at: the com.google.common.collect.Multimap

Windows Registry key for “check whether IE is the default browser”?

谁都会走 提交于 2019-11-28 20:04:27
问题 In IE under Tools-> Internet Options -> Programs there's a checkbox labelled "Tell me if Internet Explorer is not the default web browser." What's the registry key that corresponds to this checkbox? The reason I ask is that I want to suppress this check programmatically. Clarification: I don't want to find out the default browser, I want to stop IE checking if it is the default browser when it starts up. 回答1: It's been answered in various ways over the web and here; here's one question which

Prevent default behavior in text input while pressing arrow up

给你一囗甜甜゛ 提交于 2019-11-28 19:50:28
问题 I’m working with basic HTML <input type="text"/> text field with a numeric value. I’m adding JavaScript event keyup to see when user presses arrow up key ( e.which == 38 ) – then I increment the numeric value. The code works well, but there’s one thing that bugs me. Both Safari/Mac and Firefox/Mac move cursor at the very beginning when I’m pressing the arrow up key. This is a default behavior for every <input type="text"/> text field as far as I know and it makes sense. But this creates not a

How do :default => 0 and :null => false differ for integer fields in migrations?

馋奶兔 提交于 2019-11-28 19:05:47
If I use a migration to update a database, and I add an integer field like this: t.integer :foo :default => 0, :null => false What is the default state of existing and new records in the database? I hoping the answer is: - Both will read back foo as 0. Is default => 0 necessary, if I have :null => false? Just trying to understand the difference between the two... :null => false tells your database not to accept NULL values. :default => 0 does two things: Tell your database to use '0' as the default value when NULL or nothing is specified in a query. Tell rails to use '0' as a default value

Setting default value for Foreign Key attribute

烈酒焚心 提交于 2019-11-28 18:32:15
What is the best way to set a default value for a foreign key field in a model? Suppose I have two models, Student and Exam with student having exam_taken as foreign key. How would I ideally set a default value for it? Here's a log of my effort class Student(models.Model): .... ..... exam_taken = models.ForeignKey("Exam", default=1) Works, but have a hunch there's a better way. def get_exam(): return Exam.objects.get(id=1) class Student(models.Model): .... ..... exam_taken = models.ForeignKey("Exam", default=get_exam) From here , but fails with tables does not exist error while syncing. Any

Require a default constructor in java?

假如想象 提交于 2019-11-28 18:26:38
Is there any way to require that a class have a default (no parameter) constructor, aside from using a reflection check like the following? (the following would work, but it's hacky and reflection is slow) boolean valid = false; for(Constructor<?> c : TParse.class.getConstructors()) { if(c.getParameterTypes().length == 0) { valid = true; break; } } if(!valid) throw new MissingDefaultConstructorException(...); You can build an Annotation processor for that. Annotation Processors are compiler plugins that get run at compile time. Their errors show up as compiler errors, and may even halt the

default copy constructor

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 17:50:45
Can the (implicit) default copy constructor be called for a class that has already user-defined constructor but that is not the copy constructor ? If it is possible then, suppose we define the copy constructor for the class explicitly , now can the (implicit)default constructor be called? James Kanze First, let's clarify our vocabulary a bit. A default constructor is a constructor which can be called without any arguments. A copy constructor is a constructor which can be called with a single argument of the same type. Given this, a "default copy constructor" would be a constructor with a