标题互相包含在C 中
headerd include each other in c++
我试图这样做时有错误:
在main.cpp文件中 -
#include <iostream>
#include "Image.h"
using namespace std;
using namespace imaging;
int main()
{
char onoma_arxeiou[100];
cout<<"Dwse onoma arxeiou: ";
cin>>onoma_arxeiou;
Image im(5,6);
im<<onoma_arxeiou;
}
image.h
#include "ppm_format.h"
using namespace std;
namespace imaging
{
class Image
{
bool Image::operator << (std::string filename)
{
ReadPPM(filename.c_str());
}
};
和ppm.h
class Image;
//#include "Image.h"
namespace imaging
{
void ReadPPM(const char * filename);
bool WritePPM(Image & image, const char * filename);
}
但是在main
中看不到Image
有这些错误:
错误:引用"图像"是模棱两可的
Image im(5,6);
请有任何帮助吗?
ppm.h
失败的原因,您的图像有向前声明:
class Image;
这是在全局名称空间中,而不是在您的imaging
名称空间中。
要解决此问题,将您的正向声明放在imaging
名称空间内。
namespace imaging
{
class Image;
void ReadPPM(const char * filename);
/// ...
}
相关文章:
- 只要我不包含一个标题,重新定义C++关键字合法吗
- 如何确定 BMP 图像是否包含来自标题的 BGR 或 BGRA 像素
- 双重包含和仅标题库stbi_image
- C++:我需要在这里包含这个标题,我不知道为什么
- 如何包含已经包含我当前标题的其他标头
- 如何防止在标题中包含标头,以最大程度地减少包含在其他 CPP 中
- C 在多个源文件中包含具有同一类实现的不同标题文件
- 在命名空间外包含标题
- 在标题文件和CPP文件中都包含库
- 避免在标题中包含chrono
- "Error: 'dungeon_t' was not declared in this scope"但包含在标题中
- 我如何编写一个脚本来创建.cpp文件,其中包含所有标题内容
- 如何在C 项目中包含具有相似名称的标题文件
- 标题互相包含在C 中
- 如果我在标题文件中使用关键字的声明,则应该在定义本身中包含相同的关键字
- 在标题文件名中包含期限
- C 使用c库,其中包含标题文件中定义的全局变量
- 通过自制软件安装 freetype,似乎无法正确包含标题
- C++简单的类程序无法编译。我搞砸了包含标题吗? 'Error redefinition of a class'
- 前向声明/最好何时包含标题