如何从基类继承结构成员
How to inherit structure members from base class?
我写了一个简单的c++代码,用继承的概念做一些库管理。我遇到了一些继承结构问题和一些全局变量问题。我的代码:
头文件:
#ifndef LIBRARY_H
#define LIBRARY_H
#include <string.h>
#include <iostream>
using namespace std;
static int count_emp;
static int m_nCountBook;
class employee
{
protected:
typedef struct
{
char employee_name[20];
int employee_id;
char employee_dept[20];
char status_emp[10];
} stemp;
public:
stemp emp[10];
void add_employee();
void display_employee();
};
class library : public employee
{
protected:
typedef struct
{
char book_name[20];
int book_id;
char author[20];
char status_book;
} stlib;
public:
stlib lib[10];
void addBook();
void showBook();
void bookTaken();
void bookReturn();
};
#endif
这个概念是当我在另一个文件中实现bookTaken()
函数时,应该检查员工id并添加所取的status_emp
。如果以前的员工状态被占用,则不允许。我如何定义使用这两个结构的功能?还有一个问题是static int count_emp
;static int m_nCountBook
;是静态的。我怎样才能进入另一个文件?
删除两个全局变量。它们应该是库类的实例字段。
如果正确使用stl
,很可能根本不需要它们。例如,将所有数组替换为std::vector
s,除了应该为std::string
的char数组。
相关文章:
- 具有结构成员char数组的sscanf
- 仅使用结构名称访问结构成员
- 使用 structType*& 赋给结构成员
- 使用结构成员指针在C++中填充结构
- 聚合初始化,将成员指针设置为同一结构成员
- 为什么结构化绑定不使用"auto&"返回对结构成员的引用,而是返回成员本身
- 是否可以将结构数组别名为结构成员数组?
- 结构成员在访问时被清除
- 如何指示结构成员没有锯齿?
- 为什么继承的结构成员在联合中无法访问?
- 尝试在 qml 中访问结构成员的 QList
- C++/CLI -- 访问结构成员
- 调用在类中声明的结构成员
- 对结构成员的临时绑定引用
- 无法使用 strcpy 将字符串复制到静态结构成员
- 为什么类成员数据必须是静态的才能被模板化类的模板化结构成员访问
- 填充模板化结构类型的结构成员
- C/C++intellisense 0.26.1不显示结构成员列表
- 在源文件中创建具有结构成员的结构
- 如何访问结构成员作为指针