forward-declaration - 朋友声明调用“C++ 需要所有声明的类型说明符”
问题描述
当我只包含我的“Int.h”时,朋友声明会调用“C++ 需要所有声明的类型说明符”。当我只写前向声明“class Int;”时它运行良好 并在 cpp 文件中包含“Int.h”。
#ifndef _MY_ARRAY_H_
#define _MY_ARRAY_H_
// class Int;
#include "Int.h"
class MyArray {
friend Int; //error: C++ requires a type specifier for all declarations
public:
MyArray(int dim, int *size);
Int operator[](int n);
private:
int mDim;
int *mSize;
int *mData;
};
#endif
在我看来,它不需要“前向声明”,因为“Int.h”文件中有一个“Int”类声明。但确实如此。为什么?
解决方案
推荐阅读
- spring - 如何以我想要的方式使用@JSONManagedReference 进行测试?
- javascript - 通过json访问一个URL,可以通过提供User/Pass在chrome中打开
- internet-explorer - 基于处理器架构编辑/安装注册表文件 (.reg)
- python - Python在文件中匹配后替换单词
- excel - 在 Outlook 中粘贴 Excel 范围
- machine-learning - 如何检查文本是否有信息请求
- sql - 需要帮助回答有关 sql 数据完整性的问题
- python - 打印嵌套字典中的数字产品
- javascript - 如何使用 ES6 Javascript 类验证和显示表单数据
- github - github克隆分支和合并过程