Search Results

Search found 48020 results on 1921 pages for 'void return'.

Page 8/1921 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Should a setter return immediately if assigned the same value?

    - by Andrei Rinea
    In classes that implement INotifyPropertyChanged I often see this pattern : public string FirstName { get { return _customer.FirstName; } set { if (value == _customer.FirstName) return; _customer.FirstName = value; base.OnPropertyChanged("FirstName"); } } Precisely the lines if (value == _customer.FirstName) return; are bothering me. I've often did this but I am not that sure it's needed nor good. After all if a caller assigns the very same value I don't want to reassign the field and, especially, notify my subscribers that the property has changed when, semantically it didn't. Except saving some CPU/RAM/etc by freeing the UI from updating something that will probably look the same on the screen/whatever_medium what do we obtain? Could some people force a refresh by reassigning the same value on a property (NOT THAT THIS WOULD BE A GOOD PRACTICE HOWEVER)? 1. Should we do it or shouldn't we? 2. Why?

    Read the article

  • how to return response from post in a variable? jQuery

    - by robertdd
    i use this function to return the response of post: $.sendpost = function(){ return jQuery.post('inc/operations.php', {'operation':'test'}, "json"); }, i want to make something like this: in: $.another = function(){ var sendpost = $.sendpost(); alert(sendpost); } but i get: [object XMLHttpRequest] if i print the object with: jQuery.each(sendpost, function(i, val) { $(".displaydetails").append(i + " => " + val + "<br/>"); }); i get: details abort => function () { x && h.call(x); g("abort"); } dispatchEvent => function dispatchEvent() { [native code] } removeEventListener => function removeEventListener() { [native code] } open => function open() { [native code] } setRequestHeader => function setRequestHeader() { [native code] } onreadystatechange => [xpconnect wrapped nsIDOMEventListener] send => function send() { [native code] } readyState => 4 status => 200 getResponseHeader => function getResponseHeader() { [native code] } responseText => mdaaa from php how to return only the response in the variable?

    Read the article

  • Object inheritance and method parameters/return types - Please check my logic

    - by user2368481
    I'm preparing for a test and doing practice questions, this one in particular I am unsure I did correctly: We are given a very simple UML diagram to demonstrate inheritance: I hope this is clear, it shows that W inherits from V and so on: |-----Y V <|----- W<|-----| |-----X<|----Z and this code: public X method1(){....} method2(new Y()); method2(method1()); method2(method3()); The questions and my answers: Q: What types of objects could method1 actually return? A: X and Z, since the method definition includes X as the return type and since Z is a kind of X is would be OK to return either. Q: What could the parameter type of method2 be? A: Since method2 in the code accepts Y, X and Z (as the return from method1), the parameter type must be either V or W, as Y,X and Z inherit from both of these. Q: What could return type of method3 be? A: Return type of method3 must be V or W as this would be consistent with answer 2.

    Read the article

  • How to get the result for return statement from JSON parsing?

    - by blankon91
    I've follow the code for parsing the value with JSON from here, but I get the problem in my return statement. I want to put the parsing result into my return statement. How to do that? Here is my code: public String MASUK(String user, String password) { SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME); PropertyInfo pi = new PropertyInfo(); pi.setName("ccduser"); pi.setValue(user); pi.setType(String.class); request.addProperty(pi); PropertyInfo pi2 = new PropertyInfo(); pi2.setName("password"); pi2.setValue(password); pi2.setType(String.class); request.addProperty(pi2); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); try { httpTransport.call(SOAP_ACTION, envelope); SoapObject resultSOAP = (SoapObject) envelope.bodyIn; /* gets our result in JSON String */ String ResultObject = resultSOAP.getProperty(0).toString(); resultSOAP = (SoapObject) envelope.bodyIn; ResultObject = resultSOAP.getProperty(0).toString(); if (ResultObject.startsWith("{")) { // if JSON string is an object JSONObj = new JSONObject(ResultObject); Iterator<String> itr = JSONObj.keys(); while (itr.hasNext()) { String Key = (String) itr.next(); String Value = JSONObj.getString(Key); BundleResult.putString(Key, Value); // System.out.println(bundleResult.getString(Key)); } } else if (ResultObject.startsWith("[")) { // if JSON string is an array JSONArr = new JSONArray(ResultObject); System.out.println("length" + JSONArr.length()); for (int i = 0; i < JSONArr.length(); i++) { JSONObj = (JSONObject) JSONArr.get(i); BundleResult.putString(String.valueOf(i), JSONObj.toString()); // System.out.println(bundleResult.getString(i)); } } } catch (Exception exception) { } return null; }

    Read the article

  • C++ -- return x,y; The point?

    - by Earlz
    Hello, I have been programming in C and C++ for a few years and now I'm taking a college course in it and our book had a function like this int foo(){ int x=0; int y=20; return x,y; //y is always returned } I have never seen such syntax. In fact, I never see the , operator used outside of parameter lists. If y is always returned though, then what is the point? Is there a case where a return statement would need to be created like this? (Also, I tagged C as well because it applies to both, though my book specifically is C++)

    Read the article

  • Return lines in input code causing gaps/whitespace between elements in output?

    - by Jenny Zhang
    I am trying to put images next to each other on a webpage. Here is my HTML: <img class="pt" src="Yellow Tulip.jpg" title="Yellow Tulip" alt="Yellow Tulip" /> <img class="pt" src="Pink Tulip.jpg" title="Pink Tulip" alt="Pink Tulip" /> <img class="pt" src="Purple Tulip.jpg" title="Purple Tulip" alt="Purple Tulip" /> However, on my webpage, this shows a gap between each image. I've noticed that once I remove the return line that makes the elements separate and readable and instead just put all the elements on one line, the gaps go away. <img class="pt" src="Yellow Tulip.jpg" title="Yellow Tulip" alt="Yellow Tulip" /><img class="pt" src="Pink Tulip.jpg" title="Pink Tulip" alt="Pink Tulip" /><img class="pt" src="Purple Tulip.jpg" title="Purple Tulip" alt="Purple Tulip" /> Is there anyway I can achieve the output of the latter but still have the code/input look like the former? I really like the readability that the return lines (enter spaces) bring to the code, but I don't want the whitespace it creates on the actual page. If someone could explain why this is and/or how to fix it, I'd be really grateful! :)

    Read the article

  • Converting C# void* to byte[]

    - by Yurik
    In C#, I need to write T[] to a stream, ideally without any additional buffers. I have a dynamic code that converts T[] (where T is a no-objects struct) to a void* and fixes it in memory, and that works great. When the stream was a file, I could use native Windows API to pass the void * directly, but now I need to write to a generic Stream object that takes byte[]. Can anyone suggest a hack way to create a dummy array object which does not actually have any heap allocations, but rather points to an already existing (and fixed) heap location. This is the pseudo-code that I need: void Write(Stream stream, T[] buffer) { fixed( void* ptr = &buffer ) // done with dynamic code generation { int typeSize = sizeof(T); // done as well byte[] dummy = (byte[]) ptr; // <-- how do I create this fake array? stream.Write( dummy, 0, buffer.Length*typeSize ); } }

    Read the article

  • How to gain Access to member variables of a class using void pointer but Not Object

    - by mahesh
    Hi, I am trying to access member variables of a class without using object. please let me know how to go about. class TestMem { int a; int b; public: TestMem(){} void TestMem1() { a = 10; b = 20; } }; void (TestMem::*pMem)(); int main(int argc, char* argv[]) { TestMem o1; pMem = &(TestMem::TestMem1); void *p = (void*)&pMem; // How to access a & b member variables using variable p getch(); return 0; }

    Read the article

  • Returning a variable in a public void...

    - by James Rattray
    Hello, I'm abit new to programming Android App's, however I have come across a problem, I can't find a way to make global variables -unlike other coding like php or VB.NET, are global variables possible? If not can someone find a way (and if possible implement the way into the code I will provide below) to get a value from the variable 'songtoplay' so I can use in another Public Void... Here is the code: final Spinner hubSpinner = (Spinner) findViewById(R.id.myspinner); ArrayAdapter adapter = ArrayAdapter.createFromResource( this, R.array.colours, android.R.layout.simple_spinner_item); adapter .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); hubSpinner.setAdapter(adapter); // hubSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { //code Object ttestt = hubSpinner.getSelectedItem(); final String test2 = ttestt.toString(); Toast message1 = Toast.makeText(Textbox.this, test2, Toast.LENGTH_LONG); message1.show(); String songtoplay = test2; // Need songtoplay to be available in another 'Public Void' } public void onNothingSelected(AdapterView<?> parentView) { //Code } }); Basically, it gets the value from the Spinner 'hubSpinner' and displays it in a Toast. I then want it to return a value for string variable 'songtoplay' -or find a way to make it global or useable in another Public Void, (Which is will a button, -loading the song to be played) Please help me, Thanks alot. James

    Read the article

  • Passing Derived Class Instances as void* to Generic Callbacks in C++

    - by Matthew Iselin
    This is a bit of an involved problem, so I'll do the best I can to explain what's going on. If I miss something, please tell me so I can clarify. We have a callback system where on one side a module or application provides a "Service" and clients can perform actions with this Service (A very rudimentary IPC, basically). For future reference let's say we have some definitions like so: typedef int (*callback)(void*); // This is NOT in our code, but makes explaining easier. installCallback(string serviceName, callback cb); // Really handled by a proper management system sendMessage(string serviceName, void* arg); // arg = value to pass to callback This works fine for basic types such as structs or builtins. We have an MI structure a bit like this: Device <- Disk <- MyDiskProvider class Disk : public virtual Device class MyDiskProvider : public Disk The provider may be anything from a hardware driver to a bit of glue that handles disk images. The point is that classes inherit Disk. We have a "service" which is to be notified of all new Disks in the system, and this is where things unravel: void diskHandler(void *p) { Disk *pDisk = reinterpret_cast<Disk*>(p); // Uh oh! // Remainder is not important } SomeDiskProvider::initialise() { // Probe hardware, whatever... // Tell the disk system we're here! sendMessage("disk-handler", reinterpret_cast<void*>(this)); // Uh oh! } The problem is, SomeDiskProvider inherits Disk, but the callback handler can't receive that type (as the callback function pointer must be generic). Could RTTI and templates help here? Any suggestions would be greatly appreciated.

    Read the article

  • Compiler error: Variable or field declared void [closed]

    - by ?? ?
    i get some error when i try to run this, could someone please tell me the mistakes, thank you! [error: C:\Users\Ethan\Desktop\Untitled1.cpp In function `int main()': 25 C:\Users\Ethan\Desktop\Untitled1.cpp variable or field `findfactors' declared void 25 C:\Users\Ethan\Desktop\Untitled1.cpp initializer expression list treated as compound expression] #include<iostream> #include<cmath> using namespace std; void prompt(int&, int&, int&); int gcd(int , int , int );//3 input, 3 output void findfactors(int , int , int, int, int&, int&);//3 input, 2 output void display(int, int, int, int, int);//5 inputs int main() { int a, b, c; //The coefficients of the quadratic polynomial int ag, bg, cg;//value of a, b, c after factor out gcd int f1, f2; //The two factors of a*c which add to be b int g; //The gcd of a, b, c prompt(a, b, c);//Call the prompt function g=gcd(a, b, c);//Calculation of g void findfactors(a, b, c, f1, f2);//Call findFactors on factored polynomial display(g, f1, f2, a, c);//Call display function to display the factored polynomial system("PAUSE"); return 0; } void prompt(int& num1, int& num2, int& num3) //gets 3 ints from the user { cout << "This program factors polynomials of the form ax^2+bx+c."<<endl; while(num1==0) { cout << "Enter a value for a: "; cin >> num1; if(num1==0) { cout<< "a must be non-zero."<<endl; } } while(num2==0 && num3==0) { cout << "Enter a value for b: "; cin >> num2; cout << "Enter a value for c: "; cin >> num3; if(num2==0 && num3==0) { cout<< "b and c cannot both be 0."<<endl; } } } int gcd(int num1, int num2, int num3) { int k=2, gcd=1; while (k<=num1 && k<=num2 && k<=num3) { if (num1%k==0 && num2%k==0 && num3%k==0) gcd=k; k++; } return gcd; } void findFactors(int Ag, int Bg, int Cg,int& F1, int& F2) { int y=Ag*Cg; int z=sqrt(abs(y)); for(int i=-z; i<=z; i++) //from -sqrt(|y|) to sqrt(|y|) { if(i==0)i++; //skips 0 if(y%i==0) //if i is a factor of y { if(i+y/i==Bg) //if i and its partner add to be b F1=i, F2=y/i; else F1=0, F2=0; } } } void display(int G, int factor1, int factor2, int A, int C) { int k=2, gcd1=1; while (k<=A && k<=factor1) { if (A%k==0 && factor1%k==0) gcd1=k; k++; } int t=2, gcd2=1; while (t<=factor2 && t<=C) { if (C%t==0 && factor2%t==0) gcd2=t; t++; } cout<<showpos<<G<<"*("<<gcd1<<"x"<<gcd2<<")("<<A/gcd1<<"x"<<C/gcd2<<")"<<endl; }

    Read the article

  • C++: why a self pointer of a struct automatically changes to void*

    - by Stone
    struct ptr{ int node; ptr *next; ptr(){} ptr(int _node, ptr *_next){ node=_node; next=_next; } }; struct list_t{ ptr *sht; int size; void push(int node){ size++; sht=new ptr(node,sht); } }shthead[100001], comp[200001], tree[200001]; The struct ptr is a smart pointer, be used as a linked list. But when I debug the code in gdb, I found that the ptr*'s were all converted to void*. GDB output: (gdb) pt ptr type = struct ptr { int node; void *next; public: ptr(void); ptr(int, void *); } However, I can still see the data of the struct if I covert them back to ptr* in gdb. What's the reason for this please?

    Read the article

  • Event Dispatching, void pointer and alternatives

    - by PeeS
    i have my event dispatching / handling functionality working fine, but there is one issue that i need to resolve. Long story short, here are the details. // The event structure struct tEventMessage { // Type of the event int Type; // (void*) Allows those to be casted into per-Type objects void *pArgument1; void *pArgument2; }; I am sending events from different modules in my engine by using the above structure, which requires a pointer to an argument. All messages are queued, and then dispatched on the next ::Tick(). It works fine, untill i try to send something that doesn't exist in next ::Tick, for example: When a mouse click is being handled, it calculates the click coordinates in world space. This is being sent with a pointer to a vector representing that position, but after my program quits that method, this pointer gets invalid obviously, cause local CVector3 is destructed: CVector2 vScreenSpacePosition = vAt; CVector3 v3DPositionA = CVector3(0,0,0); CVector3 v3DPositionB = CVector3(0,0,0); // Screen space to World space calculation for depth zNear v3DPositionA = CMath::UnProject(vScreenSpacePosition, m_vScreenSize, m_Level.GetCurrentCamera()->getViewMatrix(), m_Level.GetCurrentCamera()->getProjectionMatrix(), -1.0 ); // Screen space to World space calculation for depth zFar v3DPositionB = CMath::UnProject(vScreenSpacePosition, m_vScreenSize, m_Level.GetCurrentCamera()->getViewMatrix(), m_Level.GetCurrentCamera()->getProjectionMatrix(), 1.0); // Send zFar position and ScreenSpace position to the handlers // Obviously both vectors won't be valid after this method quits.. CEventDispatcher::Get()->SendEvent(CIEventHandler::EVENT_SYSTEM_FINGER_DOWN, static_cast<void*>(&v3DPositionB), static_cast<void*>(&vScreenSpacePosition)); What i want to ask is, if there is any chance i could make my tEventMessage more 'template', so i can handle sending objects like in the above situation + use what is already implemented? Can't figure it out at the moment.. What else can be done here to allow me to pass some locally available data ? Please can somebody shed a bit of light on this please?

    Read the article

  • How do you return a pointer to a base class with a virtual function?

    - by Nick Sweet
    I have a base class called Element, a derived class called Vector, and I'm trying to redefine two virtual functions from Element in Vector. //element.h template <class T> class Element { public: Element(); virtual Element& plus(const Element&); virtual Element& minus(const Element&); }; and in another file //Vector.h #include "Element.h" template <class T> class Vector: public Element<T> { T x, y, z; public: //constructors Vector(); Vector(const T& x, const T& y = 0, const T& z =0); Vector(const Vector& u); ... //operations Element<T>& plus(const Element<T>& v) const; Element<T>& minus(const Element<T>& v) const; ... }; //sum template <class T> Element<T>& Vector<T>::plus(const Element<T>& v) const { Element<T>* ret = new Vector((x + v.x), (y + v.y), (z + v.z)); return *ret; } //difference template <class T> Element<T>& Vector<T>::minus(const Element<T>& v) const { Vector<T>* ret = new Vector((x - v.x), (y - v.y), (z - v.z)); return *ret; } but I always get error: 'const class Element' has no member named 'getx' So, can I define my virtual functions to take Vector& as an argument instead, or is there a way for me to access the data members of Vector through a pointer to Element? I'm still fairly new to inheritance polymorphism, fyi.

    Read the article

  • Can I make a LaTeX macro 'return' a filename?

    - by drfrogsplat
    I'm writing my thesis/dissertation and since its an on-going work I don't always have the actual images ready for the figures I put into my document, but for various reasons want to automatically have it substitute a dummy figure in place when the included graphics file doesn't exist. E.g. I can do something like \includegraphics[width=8cm]{\chapdir/figures/fluxcapacitor} (where \chapdir is a macro for my 'current' chapter directory, e.g. \def\chapdir{./ch_timetravel} and if there's no ./ch_timetravel/figures/fluxcapacitor.jpg it'll insert ./commands/dummy.jpg instead. I've structured my macros (perhaps naïvely?) so that I have a macro (\figFileOrDummy) that determines the appropriate file to include by checking if the argument provided to it exists, so that I can call \includegraphics[properties]{\figFileOrDummy{\chapdir/figures/fluxcapacitor}}. Except I'm getting various errors depending on how I try to call this, which seem to suggest that I'm approaching the problem in a fundamentally flawed way as far as 'good LaTeX programming' goes. Here's the macro to check if the file exists (and 'return' either filename or the dummy filename): \newcommand{\figFileOrDummy}[1]{% % Figure base name (no extension) to be used if the file exists \def\fodname{#1}% \def\dummyfig{commands/dummy}% % Check if output is PS (.EPS) or PDF (.JPG/.PDF/.PNG/...) figures \ifx\pdfoutput\undefined% % EPS figures only \IfFileExists{\fodname.eps}{}{\def\fodname{\dummyfig}}% \else% % Check existence of various extensions: PDF, TIF, TIFF, JPG, JPEG, PNG, MPS \def\figtest{0}% flag below compared to this value \IfFileExists{\fodname.pdf}{\def\figfilenamefound{1}}{\def\figfilenamefound{0}}% \IfFileExists{\fodname.jpg}{\def\figfilenamefound{1}}{}% \IfFileExists{\fodname.png}{\def\figfilenamefound{1}}{}% % and so on... % If no files found matching the filename (flag is 0) then use the dummy figure \ifx\figfilenamefound\figtest% \def\fodname{\dummyfig}% \fi% \fi% % 'return' the filename \fodname% }% Alternatively, here's a much simpler version which seems to have similar problems: \newcommand{\figFileOrDummy}[1]{% \def\dummyfig{commands/dummy}% \dummyfig% } The \def commands seems to be processed after the expansion of the macro they're trying to define, so it ends up being \def {commands/dummy}... (note the space after \def) and obviously complains. Also it seems to treat the literal contents of the macro as the filename for \includegraphics, rather than resolving/expanding it first, so complains that the file '\def {commands/dummy}... .png' doesn't exist.. I've tried also doing something like \edef\figfilename{\figFileOrDummy{\chapdir/figures/fluxcapacitor}} to try to force it to make \figfilename hold just the value rather than the full macro, but I get an Undefined control sequence error complaining the variables I'm trying to \def in the \figFileOrDummy macro are undefined. So my question is either How do I make this macro expand properly?; or If this is the wrong way of structuring my macros, how should I actually structure such a macro, in order to be able to insert dummy/real figures automatically?; or Is there a package that already handles this type of thing nicely that I've overlooked? I feel like I'm missing something pretty fundamental here...

    Read the article

  • Does Ruby have a special stack for return value?

    - by prosseek
    The following Ruby code def a(b,c) b+c end is the same as follows with Python def a(b,c): return b+c It looks like that ruby has the special stack that stores the final evaluation result and returns the value when a function is called. If so, what's the name of the stack, and how can I get that stack? If not, how does the Ruby code work without returning something?

    Read the article

  • Python C API return more than one value / object without building a tuple [migrated]

    - by Grisu
    I got the following problem. I have written a C-Extension to Python(2.7 / 3.2) to interface a self written software library. Unfortunately I need to return two values from the function where the last one is optional. In Python I tried def func(x,y): return x+y, x-y test = func(13,4) but test is a tuple. If I write test1,test2 = func(13,4) I got both values separated. Is there a possibility to return only one value without unpacking the tuple, i.e. the second(,.. third, ..fourth) value gets neglected? And if such a solution existst, how does it look for the C-API? Because return Py_BuildValue("ii",x+y,x-y); results in a tuple as well.

    Read the article

  • Should I return iterators or more sophisticated objects?

    - by Erik
    Say I have a function that creates a list of objects. If I want to return an iterator, I'll have to return iter(a_list). Should I do this, or just return the list as it is? My motivation for returning an iterator is that this would keep the interface smaller -- what kind of container I create to collect the objects is essentially an implementation detail On the other hand, it would be wasteful if the user of my function may have to recreate the same container from the iterator which would be bad for performance.

    Read the article

  • Is it better to return NULL or empty values from functions/methods where the return value is not present?

    - by P B
    I am looking for a recommendation here. I am struggling with whether it is better to return NULL or an empty value from a method when the return value is not present or cannot be determined. Take the following two methods as an examples: string ReverseString(string stringToReverse) // takes a string and reverses it. Person FindPerson(int personID) // finds a Person with a matching personID. In ReverseString(), I would say return an empty string because the return type is string, so the caller is expecting that. Also, this way, the caller would not have to check to see if a NULL was returned. In FindPerson(), returning NULL seems like a better fit. Regardless of whether or not NULL or an empty Person Object (new Person()) is returned the caller is going to have to check to see if the Person Object is NULL or empty before doing anything to it (like calling UpdateName()). So why not just return NULL here and then the caller only has to check for NULL. Does anyone else struggle with this? Any help or insight is appreciated.

    Read the article

  • How to accomplish covariant return types when returning a shared_ptr?

    - by Kyle
    using namespace boost; class A {}; class B : public A {}; class X { virtual shared_ptr<A> foo(); }; class Y : public X { virtual shared_ptr<B> foo(); }; The return types aren't covariant (nor are they, therefore, legal), but they would be if I was using raw pointers instead. What's the commonly accepted idiom to work around this, if there is one?

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >