0

I have array of objects

MyClass MyArr[10];

In method of one element of array ( MyArr[j] ) I need to access to method of another element in this array ( MyArr[i].Method2(arg) ).

How I Can do this?

Access from one element of array to another element of array?

2
  • 1
    Why do you need to do this? What is MyClass? Why are the instances in an array? Commented Dec 11, 2010 at 12:41
  • mo details about application: MyArr - is the global storage of measured and calculated values in reality his consist 10 000 elements. Measured part of elements paken his parameters from ethernet exchange (for example 1, 2,3, 10,25 element) in non determinated siquence and time periods, calculeted elements takes his parameters from measured elements (10-th element takes parametersa from 1-st and 2-nd elements parameters). Indexes of measured and calculated elements are configured of user. Parameters of all elements of array are stored in database asichronous in separated thread. Commented Dec 11, 2010 at 13:09

2 Answers 2

1

There's lots of ways. Some are:

  • make MyArr a static variable of the MyClass class
  • pass MyArr[i] as a parameter to the method call on MyArr[j]
  • construct each object passing in a pointer or reference to the other instance
3
  • In real i-th element need access to several elements of array (for example 1,2 ,5 for 9-th element). Commented Dec 11, 2010 at 13:22
  • That would suggest going with the first option: every element has access to the class' static variables. Commented Dec 11, 2010 at 13:27
  • @Neuronet: yep, that's what I meant. Commented Dec 11, 2010 at 13:33
0

You can either pass the array to each object, or you might find a linked list worth trying

1
  • MyArr is a global static array. And created on compilation stage. In your way we need inicialise parameter of array elements in loop on start of application. Is there another way? Commented Dec 11, 2010 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.