A basic question
1 posts in topic
Flat View  Flat View

Posted By:   liat_even
Posted On:   Sunday, April 14, 2002 08:01 AM

I have 2 classes: x,y.
x is calling the method a(int p), which is a public member of class y. I want to pass a value to method a (using the parameter p), to change p in the method, and that x will use the updated value.
When I try doing it as if the method a was a member in class x, the value of p isn't updated (after returning from a).
What should I do to solve it?

Re: A basic question

Posted By:   Terry_Laurenzo  
Posted On:   Sunday, April 14, 2002 10:44 AM

The most straight-forward approach to doing this(although generally not the best way) is to pass an array instead of a primitive value. The invoked method can change the contents of the array and the caller can access these changes. This will give you the pass-by-reference semantics that it looks like you're after.

For anything but the most trivial cases, though, your difficulty probably indicates a design flaw in your classes. Consider refactoring your classes so that your argument "p" is itself a class.

About | Sitemap | Contact