• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help me find this please....  RSS feed

 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to return the summation of a variable ?

I have two classes. One class with a private variable and gettter, setter method for it. It has a constructor which initializes the variable.

Another class has a method which returns the above said class's object. So, when i call this method it shoudl give me the summation of that variable in first class.




 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell us what you have achieved so far, and use a more specific thread subject.
 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


2nd class:
-----------




my class gets populated on the native side. Say, if two objects are created in native side, my will be called twice and my.i will have two values each per object. Now, i should get the summation of these two object's in getit() method in the 2nd class, which returns an object of my class. In PSVM, i ll create instantiate mine class and call getit(), which should return the summation of i, for the no of objects it created.

How to do this? I am breaking my head for 2 days now.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So, basically... you want a sum of every my.i variables, even though you don't have access to the my objects?

The easiest way to do that is to have the my class keep track of them. Probably add them to a list when they are constructed. Of course, if you do that, then they will always be reachable, hence, not garbage collected. And you will get a sum of all the my objects, not the one that are reachable from outside of the my list.

To partially improve that, I guess you can make the list weakly referenced, but again, the list won't be just my objects that are strongly reachable.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!