访问数组中对象的成员函数 [英] Accessing a member function of an object in an array

查看:114
本文介绍了访问数组中对象的成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组充满了我创建的类的对象。我想访问他们每个人的功能,但我不知道如何。我用指针试了一下,但没有奏效。

I have an array full with objects of a class I created. I want to access functions of each of them but I don't know how. I tried it with a pointer but it didn't work. Sorry for the question being noobie, I'm a beginner.

推荐答案

您应该可以像访问任何数据元素一样访问数组元素其他对象:

You should be able to access an array element just like any other object:

MyClass array[42];
array[12].do_something();

如果这不是您想要做的,请描述您在做什么详细信息(理想情况下使用示例代码),以及出错的地方(包括您收到的任何错误消息)。

If that's not what you're trying to do, then please describe what you're doing in more detail (ideally with example code), and what's going wrong (including whatever error messages you get).

这篇关于访问数组中对象的成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆