简体   繁体   English

C ++对象数组。 一个元素访问数组中另一个元素的方法

[英]C++ array of objects. One element to access method of another element in array

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) ) . 在数组一个元素( MyArr[j] )方法中,我需要访问此数组中另一个元素( MyArr[i].Method2(arg) )

How I Can do this? 我该怎么做?

Access from one element of array to another element of array? 从数组的一个元素访问数组的另一个元素?

There's lots of ways. 有很多方法。 Some are: 一些是:

  • make MyArr a static variable of the MyClass class 使MyArr成为MyClass类的静态变量
  • pass MyArr[i] as a parameter to the method call on MyArr[j] MyArr[i]作为参数传递给MyArr[j]上的方法调用
  • construct each object passing in a pointer or reference to the other instance 构造每个传入另一个实例的指针或引用的对象

您可以将数组传递给每个对象,也可以找到值得尝试的链表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM