Search Results

Search found 15081 results on 604 pages for 'passing by reference'.

Page 86/604 | < Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >

  • How to do cleanup reliably in python?

    - by Cheery
    I have some ctypes bindings, and for each body.New I should call body.Free. The library I'm binding doesn't have allocation routines insulated out from the rest of the code (they can be called about anywhere there), and to use couple of useful features I need to make cyclic references. I think It'd solve if I'd find a reliable way to hook destructor to an object. (weakrefs would help if they'd give me the callback just before the data is dropped. So obviously this code megafails when I put in velocity_func: class Body(object): def __init__(self, mass, inertia): self._body = body.New(mass, inertia) def __del__(self): print '__del__ %r' % self if body: body.Free(self._body) ... def set_velocity_func(self, func): self._body.contents.velocity_func = ctypes_wrapping(func) I also tried to solve it through weakrefs, with those the things seem getting just worse, just only largely more unpredictable. Even if I don't put in the velocity_func, there will appear cycles at least then when I do this: class Toy(object): def __init__(self, body): self.body.owner = self ... def collision(a, b, contacts): whatever(a.body.owner) So how to make sure Structures will get garbage collected, even if they are allocated/freed by the shared library? There's repository if you are interested about more details: http://bitbucket.org/cheery/ctypes-chipmunk/

    Read the article

  • most popular j2ee based websites

    - by krishna
    J2EE as I understand is used to build Enterprise applications. My question is :What are the most popular public facing(internet) sites using j2ee stack. The one's that I know of are : linkedIn.com ,evite.com and sun ibm and oracle (obviously) Eclipse.org uses php, I wonder why? If you have worked on/know any other sites, can your share your experience and also the technologies used(if that's not an issue)? EDIT:It doesn't have to use the full stack. EDIT : There are quite a few ecommerce websites like bestbuy.com. I know this bcos I worked with the ATG(atg.com) ecommerce suite and their website lists their clients. Iam looking for those kind of examples and also your experience working on them. Please limit to only internet sites

    Read the article

  • O'Reilly Safari Books Alternatives?

    - by Steve
    I have a subscription to the whole library, which I find incredibly useful. Are there any similar products out there with as comprehensive a library? I think I'm paying about $40/month and I'm happy with the service, but if there are any cheaper alternatives out there, I'd like to take a look. Thanks.

    Read the article

  • C# 4.0 'dynamic' doesn't set ref/out arguments

    - by Buu Nguyen
    I'm experimenting with DynamicObject. One of the things I try to do is setting the values of ref/out arguments, as shown in the code below. However, I am not able to have the values of i and j in Main() set properly (even though they are set correctly in TryInvokeMember()). Does anyone know how to call a DynamicObject object with ref/out arguments and be able to retrieve the values set inside the method? class Program { static void Main(string[] args) { dynamic proxy = new Proxy(new Target()); int i = 10; int j = 20; proxy.Wrap(ref i, ref j); Console.WriteLine(i + ":" + j); // Print "10:20" while expect "20:10" } } class Proxy : DynamicObject { private readonly Target target; public Proxy(Target target) { this.target = target; } public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { int i = (int) args[0]; int j = (int) args[1]; target.Swap(ref i, ref j); args[0] = i; args[1] = j; result = null; return true; } } class Target { public void Swap(ref int i, ref int j) { int tmp = i; i = j; j = tmp; } }

    Read the article

  • Java Properties and References -- I'm not getting what I expect.

    - by Blumer
    I'm a little embarrassed to ask this as I ought to know better, but here's what I've got. I have an object "Pitcher" with an int property of "runsAllowed". I have an object Batter that has a property of "responsiblePitcher". I have an object Team that has a property "pitcher". When the batter reaches base: Batter.responsiblePitcher = Team.pitcher; All that's well and good. However, if we have a pitching change while the runner is on base, I set a new pitcher in Team.pitcher: Team.pitcher = new Pitcher(); ... and of course this changes the value of Batter.pitcher. How should I be doing things differently such that the Batter.responsiblePitcher property continues to point to the pitcher who let him on base instead of pointing at whever is in the Team.pitcher property? Again, I feel like I ought to know this already ... Thanks.

    Read the article

  • javascript "this" points to Window object again

    - by terrani
    Hello, I asked a question on http://stackoverflow.com/questions/2719643/javascript-this-points-to-window-object regarding "this" points to Window object. here is source code var archive = function(){} archive.prototype.action = { test: function(callback){ callback(); }, test2: function(){ console.log(this); } } var oArchive = new archive(); oArchive.action.test(oArchive.action.test2); Tim Down wrote "but that function is then called using callback(), which means it is not called as a method and hence this is the global object". What are differences between calling a function by its actual name and callback() as shown on the source code? How does console.log(this) in test2 points to Window when it is inside archive.action???

    Read the article

  • Returning object from function

    - by brainydexter
    I am really confused now on how and which method to use to return object from a function. I want some feedback on the solutions for the given requirements. Scenario A: The returned object is to be stored in a variable which need not be modified during its lifetime. Thus, const Foo SomeClass::GetFoo() { return Foo(); } invoked as: someMethod() { const Foo& l_Foo = someClassPInstance->GetFoo(); //... } Scneraio B: The returned object is to be stored in a variable which will be modified during its lifetime. Thus, void SomeClass::GetFoo(Foo& a_Foo_ref) { a_Foo_ref = Foo(); } invoked as: someMethod() { Foo l_Foo; someClassPInstance-GetFoo(l_Foo); //... } I have one question here: Lets say that Foo cannot have a default constructor. Then how would you deal with that in this situation, since we cant write this anymore: Foo l_Foo Scenario C: Foo SomeClass::GetFoo() { return Foo(); } invoked as: someMethod() { Foo l_Foo = someClassPInstance->GetFoo(); //... } I think this is not the recommended approach since it would incur constructing extra temporaries. What do you think ? Also, do you recommend a better way to handle this instead ?

    Read the article

  • In the following implementation of static_strlen, why are the & and parentheses around str necessary

    - by Ben
    If I change the type to const char str[Len], I get the following error: error: no matching function for call to ‘static_strlen(const char [5])’ Am I correct that static_strlen expects an array of const char references? My understanding is that arrays are passed as pointers anyway, so what need is there for the elements to be references? Or is that interpretation completely off-the-mark? #include <iostream> template <size_t Len> size_t static_strlen(const char (&str)[Len]) { return Len - 1; } int main() { std::cout << static_strlen("oyez") << std::endl; return 0; }

    Read the article

  • Using the word "you" in an user manual

    - by yan bellavance
    I am writing a user manual and I have come to a discussion with a colleague. He says I cannot use the word "you" anywhere in the manual. Now I remember something about this at school but that was not for writing procedures. Also, doing some googling I observed that most tutorials where using it a lot. I would prefer using it but only if this is considered good practice. what do you think?

    Read the article

  • Initializing objects on the fly

    - by pocoa
    I have a vector called players and a class called Player. And what I'm trying to do is to write: players.push_back(Player(name, Weapon(bullets))); So I want to be able to create players in a loop. But I see an error message says "no matching function for call Player::Player..." Then I've changed that to: Weapon w(bullets); Player p(name, w); players.push_back(p); Here is my Player definition: class Player { public: Player(string &name, Weapon &weapon); private string name; Weapon weapon; } I'm just trying to learn what is the difference between these definitions. And is this the right way to pass an object to an object constructor. Note: These are not my actual class definitions. I'm just trying to learn something about object oriented programming in C++ with coding it. I mean I know that Weapon should be initialized in Player :)

    Read the article

  • how to write a constructor...

    - by Nima
    is that correct to write a constructor like this? class A { A::A(const A& a) { .... } }; if yes, then is it correct to invoke it like this: A* other; ... A* instance = new A(*(other)); if not, what do you suggest? Thanks

    Read the article

  • Function with parameter type that has a copy-constructor with non-const ref chosen?

    - by Johannes Schaub - litb
    Some time ago I was confused by the following behavior of some code when I wanted to write a is_callable<F, Args...> trait. Overload resolution won't call functions accepting arguments by non-const ref, right? Why doesn't it reject in the following because the constructor wants a Test&? I expected it to take f(int)! struct Test { Test() { } // I want Test not be copyable from rvalues! Test(Test&) { } // But it's convertible to int operator int() { return 0; } }; void f(int) { } void f(Test) { } struct WorksFine { }; struct Slurper { Slurper(WorksFine&) { } }; struct Eater { Eater(WorksFine) { } }; void g(Slurper) { } void g(Eater) { } // chooses this, as expected int main() { // Error, why? f(Test()); // But this works, why? g(WorksFine()); } Error message is m.cpp: In function 'int main()': m.cpp:33:11: error: no matching function for call to 'Test::Test(Test)' m.cpp:5:3: note: candidates are: Test::Test(Test&) m.cpp:2:3: note: Test::Test() m.cpp:33:11: error: initializing argument 1 of 'void f(Test)' Can you please explain why one works but the other doesn't?

    Read the article

  • Delphi constants and references

    - by Sambatyon
    I want to pass constant references to functions in delphi, so I am sure that the referenced object won't change and to save time and memory. So I want to declare a function like function foo(var const Value : Bar) : Boolean; however this is not allowed. I thought constant values would be automatically sent as references. However I found out that it is not the case (getting the address of an object before sending it to the function gives me $12F50C and the address of the same object inside the function is $12F564) What can I do to send constant references?

    Read the article

  • "Home" of Javascript similar to python.org?

    - by drewk
    Perl, Ruby, Python, Javascript / ecmascript, PHP are all similar in the sense of being open source, open documentation, multi-platform, etc. Perl has http://www.perl.org Ruby has http://www.ruby-lang.org Python has http://www.python.org PHP has http://php.net Is there a "home" for javascript in the same sense as these other languages? When I say "home" I mean the go-to place for official documentation, specifications, source code of the language, examples, etc.

    Read the article

  • Sharing common class in wcf project

    - by Saint
    class MyCommonClass { //properties } This class should be accessible in service project wcf-client project the other for which they are references. In this common project I can't generate servicereferences. I think, I could don't generate MyCommonClass in ServiceReferences but how to mark class to be nonserializable? In properties there's IgnoreDataMemberAttribute. I tried also reuse MyCommonClass type located in common project, but it is still generated

    Read the article

  • Output is different for R-value and L-value. Why?

    - by Leonid Volnitsky
    Can someone explain to me why output for R-value is different from L-value? #include <iostream> #include <vector> using namespace std; template<typename Ct> struct ct_wrapper { Ct&& ct; // R or L ref explicit ct_wrapper(Ct&& ct) : ct(std::forward<Ct>(ct)) { std::cout << this->ct[1];}; }; int main() { // L-val vector<int> v{1,2,3}; ct_wrapper<vector<int>&> lv(v); cout << endl << lv.ct[0] << lv.ct[1] << lv.ct[2] << endl; // R-val ct_wrapper<vector<int>&&> rv(vector<int>{1,2,3}); cout << endl << rv.ct[0] << rv.ct[1] << rv.ct[2] << endl; } Output (same for gcc48 and clang32): 2 123 2 003

    Read the article

  • Is there any way to add references without recompiling in .NET?

    - by Jader Dias
    I am using a IoC Container (Castle Windsor) to instantiate classes accordingly to the configuration file. If I want to add classes from a new dll that didn't exist when I compiled the project, there is any way to do that without recompiling? Edit: As this project is a Service Host for WCF service, and the classes that I want to include after compilation are WCF Services I would like also to know if I can include endpoint information about new services without recompiling.

    Read the article

  • app.config files of referenced dlls

    - by ban-dana
    I have a Web Project (VS 2008) that references a bunch of DLLs. The DLLs are built separately, so the project references binaries and not DLL projects. Some of the DLLs have their own app.config, which I want to be copied autmatically to the web project's output directory. Is there any suitable generic way to achieve this?

    Read the article

  • What's a reasonable way to mutate a primitive variable from an anonymous Java class?

    - by Steve
    I would like to write the following code: boolean found = false; search(new SearchCallback() { @Override void onFound(Object o) { found = true; } }); Obviously this is not allowed, since found needs to be final. I can't make found a member field for thread-safety reasons. What is the best alternative? One workaround is to define final class MutableReference<T> { private T value; MutableReference(T value) { this.value = value; } T get() { return value; } void set(T value) { this.value = value; } } but this ends up taking a lot of space when formatted properly, and I'd rather not reinvent the wheel if at all possible. I could use a List<Boolean> with a single element (either mutating that element, or else emptying the list) or even a Boolean[1]. But everything seems to smell funny, since none of the options are being used as they were intended. What is a reasonable way to do this?

    Read the article

  • Assigning a variable of a struct that contains an instance of a class to another variable

    - by xport
    In my understanding, assigning a variable of a struct to another variable of the same type will make a copy. But this rule seems broken as shown on the following figure. Could you explain why this happened? using System; namespace ReferenceInValue { class Inner { public int data; public Inner(int data) { this.data = data; } } struct Outer { public Inner inner; public Outer(int data) { this.inner = new Inner(data); } } class Program { static void Main(string[] args) { Outer p1 = new Outer(1); Outer p2 = p1; Console.WriteLine("p1:{0}, p2:{1}", p1.inner.data, p2.inner.data); p1.inner.data = 2; Console.WriteLine("p1:{0}, p2:{1}", p1.inner.data, p2.inner.data); p2.inner.data = 3; Console.WriteLine("p1:{0}, p2:{1}", p1.inner.data, p2.inner.data); Console.ReadKey(); } } }

    Read the article

< Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >