我在创建一个标准向量形式的类。我一直在用一些实现了集合而不是向量的类来编写一些程序,所以我有点困惑。C++调用向量类中的私有数据成员
这里是我的类:
class Employee
{
private:
Struct Data
{
unsigned Identification_Number;
// Current capacity of the set
unsigned Department_Code;
// Department Code of employee
unsigned Salary;
// Salary of employee
str Name;
// Name of employee
}
如果我要调用私有数据成员以后,可以只是我下面?
vector<Employee> Example;
//Assume there's data in Example
cout << Example[0].Identification_Number;
cout << Example[3].Salary;
如果不是,那么apprpriate容器是什么?列表清单是否更适合处理这组数据?
为什么要将'struct'私有化,当你想公开可用?或者是'Struct Data {'错字? – Cornstalks
为什么即使有'Data'结构呢?为什么不直接将所有'Data'的成员放在Employee类中? –
这里的容器是完全不相关的,你似乎完全不知道如何访问私人会员。当然,答案是,你不会想;这就是整个问题。 – GManNickG