在其他类中使用类类型的麻烦
Trouble with using class types within other classes
我完全不知道发生了什么事。我一直在寻找对这里发生的奇怪现象的解释,但似乎我的情况在某些方面是独一无二的。我想象这是我在每个文件中包含头文件的顺序,但无济于事,我还没有找到一个似乎是解决方案的组合。
当声明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
。所以它不能再命名一个全局类型
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 模板元程序查找相似的连续类型名称
- 使用基本和用户定义类型的名称查找麻烦
- 相同的这个指针和可变类型的麻烦
- 将向量传递到C 功能时的类型麻烦
- 在其他类中使用类类型的麻烦