Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在另一个类中使用结构?_C++_Class_Struct_Fstream - Fatal编程技术网

C++ 如何在另一个类中使用结构?

C++ 如何在另一个类中使用结构?,c++,class,struct,fstream,C++,Class,Struct,Fstream,好了,大家好,我现在的任务有点问题 我有两个班,即雇员班和总经理班 在employee类中,我使用了一个结构,即 struct eInfo { char username [80]; char password [80]; int eid; }; 但是,在我的gm类中,我有一些函数依赖于employee类中的struct。比如说, void addEmployee(fstream&, int, eInfo&); void delEmployee(

好了,大家好,我现在的任务有点问题

我有两个班,即雇员班和总经理班

在employee类中,我使用了一个结构,即

struct eInfo
{
    char username [80];
    char password [80];
    int eid;
};    
但是,在我的gm类中,我有一些函数依赖于employee类中的struct。比如说,

void addEmployee(fstream&, int, eInfo&);
void delEmployee(fstream&, int, eInfo&);
void editEmployee(fstream&, int, eInfo&);
我该如何利用这一点呢

我尝试的是重新定义一个

struct eInfo
{
    char username [80];
    char password [80];
    int eid;
};
在通用汽车内部。但这并不奏效。没有语法错误,但是当我使用

流文件; 打开(“EmployeeInfo.dat”,ios::in | ios::out | ios::binary)

文件本身是空的


你知道如何解决这个问题吗?

如果结构
eInfo
员工
内部声明为,那么当你在
员工
外部时,你应该将其称为
员工::eInfo
。如果在代码> GM 内重新声明它,那么编译器将考虑<代码>::eEng/<代码>和<代码> GM::Ennule<代码>是两个不同的类。< /P> < P>在适当的头文件中声明EnFipe,然后将该头文件包含在GM类中。要创建结构,请使用以下语法。变量名只是在创建结构时使用的填充符

eInfo myStruct = {theUsername, thePassword, theEid};

你为什么不让第二个类成为第一个类的朋友呢?为什么不把
eInfo
struct带出这个类呢?