我在尝试这样做时出错:
在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);
有什么帮助吗?
答案 0 :(得分:2)
这在ppm.h
失败的原因是你有一个Image的前向声明:
class Image;
然而,这是在全局命名空间中,而不是在imaging
命名空间中。
要解决此问题,请将您的前向声明放在imaging
命名空间内。
namespace imaging
{
class Image;
void ReadPPM(const char * filename);
/// ...
}