在其他类中使用类类型的麻烦

Trouble with using class types within other classes

本文关键字:类型 麻烦 其他      更新时间:2023-10-16

我完全不知道发生了什么事。我一直在寻找对这里发生的奇怪现象的解释,但似乎我的情况在某些方面是独一无二的。我想象这是我在每个文件中包含头文件的顺序,但无济于事,我还没有找到一个似乎是解决方案的组合。

当声明LogArray[maxLength]时,我似乎得到的确切错误是"日志没有命名类型"。

我的一个类,类logmgmt:

class logmgmt
{
private:
static const int maxLength = 500;
log LogArray[maxLength];
int length;
public:
void fillLogs(int index, int iD, std::string date, double startTime, double endTime);
void displayThisLog(int index);
void setLength(int length);
};

logmgmt.cpp中的预处理器指令:

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#include "log.h"
#include "Logmgmt.h"

和main.cpp

中的指令
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
#include "employee.h"
#include "log.h"
#include "employeemgmt.h"
#include "Logmgmt.h"

删除using namespace std

这会用大量的符号名污染全局命名空间,从而导致这些冲突。

在您的示例中,函数std::log变为log。所以它不能再命名一个全局类型