reference

Returning a pointer vs. passing a reference to an object to store the answer in C++

本小妞迷上赌 提交于 2019-12-24 07:49:38
问题 I have general question regarding the use of pointers vs. references in this particular scenario. Let's say that I have a function that is going to do some computation and store the value inside an object for later use by the caller. I can implement this by using either pointers or references. Although, I would prefer using references because I trying avoiding pointers as much as possible, are there any pros/cons of one approach over the other. The code using Pointers would be as follows:

new operator and reference error

喜欢而已 提交于 2019-12-24 07:49:28
问题 $class_name = 'MDB2_Statement_'.$this->phptype; $statement = null; $obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset); The above code is old, I would like to change it into something like $class_name='MDB2_Statement_'.$this->phptype; ... $obj_=new class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset); $obj=&$obj_; But this doesn't result in correct behaviors. Could anyone offer me a

Java : declaring objects in a loop [duplicate]

流过昼夜 提交于 2019-12-24 07:25:15
问题 This question already has answers here : Efficiency of creating new objects in a loop (3 answers) Closed 5 years ago . Is there any difference between for (...) { String temp = "temp"; } and String temp; for (...) { temp = "temp"; } I mean, does Java waste many resources creating/deleting objects in loop? Thank you. 回答1: The difference is in scope of variable. Defined inside loop means visible only inside the loop. Defined outside the loop means visible inside and outside the loop. does Java

using system.windows.forms reference not showing up asp.net 4.0

情到浓时终转凉″ 提交于 2019-12-24 06:59:08
问题 I am trying to add a reference to the library stated in the question. But it is throwing an error on the 'windows' section of the library reference. Can anyone help me. Thanks! 回答1: Step 1: Go to "Solution Explorer" Step 2: Right click on "Add reference" Step 3: Search in the ".net" tab for the reference for "System.Windows.dll" Or "System.Windows.Forms.dll" (don't know which one is present there but I would prefer the later) and add it. This should resolve your problem. 来源: https:/

How can I trigger a function at Main from an instanced object — the right way?

时间秒杀一切 提交于 2019-12-24 06:47:09
问题 I want to keep total control over my game from the Main MovieClip and nowhere else. But I don't want to pass its instance through constructors neither do any .parent reference thingy from its children. Seems too workaroundish and unstable. A sample situation: public class Main extends MovieClip { public function Main() { addChild(new MainMenu()); } public function startGame():void { trace("Game started"); } } public class MainMenu extends Sprite { public function MainMenu() { var option

C# reference variable, does making one null make the other null?

≯℡__Kan透↙ 提交于 2019-12-24 05:50:56
问题 I have a question about how C# works. m_MyClass = new MyClass(); Dispatcher.m_MyClass = m_MyClass; If I set m_MyClass = null, will that automatically make Dispatcher.m_MyClass null? 回答1: No . Assigning a different value to a variable of a reference has no effect on other references. Only modifying fields of an instance or using properties or methods which modify those fields will have an effect: m_MyClass = new MyClass(); Dispatcher.m_MyClass = m_MyClass; m_MyClass.MyProp = null; //

CLSCompliant(true) drags in unused references

时间秒杀一切 提交于 2019-12-24 05:43:11
问题 Can anyone explain the following behavior? In summary, if you create multiple CLS compliant libraries in Visual Studio 2008 and have them share a common namespace root, a library referencing another library will require references to that library's references even though it doesn't consume them. It's pretty difficult to explain in a single sentence, but here are steps to reproduce the behavior (pay close attention to the namespaces): Create a library called LibraryA and add a a single class

Keeping a reference to a vector element valid after resizing

笑着哭i 提交于 2019-12-24 04:56:10
问题 If we make a reference to a vector element and then resize the vector, the reference is no longer valid, the same happens with an iterator: std::vector<int> vec{0, 1, 2, 3, 4, 5}; int& ref = vec[0]; auto itr = vec.begin(); cout << ref << " " << *itr << endl; vec[0] = 7; cout << ref << " " << *itr << endl; vec.resize(100); vec[0] = 3; cout << ref << " " << *itr << endl; Prints out: 0 0 7 7 0 0 // We expected a 3 here And I know that it would be more practical to just keep a reference to the

Problems with the DataContractSerialiser and Serializable

ぐ巨炮叔叔 提交于 2019-12-24 04:33:14
问题 I've a few Classes from a asembly wich is .Net 2.0. These Classes are makred with Serializable. In my Project, i uses this classes in my Classes, wich are marked with DataContract(IsReference=true) and DataMember. Now I have the Problem, with DataContractSerialiser that it serialises the private fields of my .Net 2.0 Classes, wich will not work. But when I use XMLSerialiser, i cannot use IsReference, and so I can also not do this. Is there a easy (simple) Solutiuon for this? Maybe a someone

In java, how do you retrieve images from a jar file?

↘锁芯ラ 提交于 2019-12-24 04:29:31
问题 I've been having problems exporting my java project to a jar (from Eclipse). There is a file that I've included in the jar named images . It contains all of the image files used by my project. The problem is, my references to those images only work when the project isn't in jar form. I can't figure out why and I'm wondering if I need to change the wording of the image references. This is what I'm doing to reference images: URL treeURL = null; Image tree = null; File pathToTheTree = new File(