【发布时间】:2017-12-15 07:55:48
【问题描述】:
class bus {
private:
string arr[10] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
public:
void reservation();
};
在这里,我有一个私有数组,我想通过 public 类中的 reservation() 访问并进行更改。
void bus::reservaton() {
cout << "What should I write in here to change the 3rd and 7th index of the
above array to \"not empty\"" << endl;
}
假设,我想让第 3 和第 7 个索引为“不为空”,我应该在那里写什么?
示例:-
string arr[10] = { "0", "1", "2", "not empty", "4", "5", "6", "not empty", "8", "9" };
我需要对主函数进行任何更改吗?如果是,那么请您帮我写下来。 谢谢。
【问题讨论】:
-
arr[3] = "not empty"? -
成员函数可以访问私有成员,否则两者都将毫无用处
-
此时最好的做法是阅读一本书或至少阅读 C++ 教程。说真的。
-
你的私教课在哪里?
标签: c++ arrays class c++11 private