header包含在main.cpp中,但在类中抛出错误

时间:2013-10-18 01:00:37

标签: c++ c

我问了这个问题here。但问题似乎是其他的东西,所以在这里重新发布..

我在main.cpp中包含来自Zbar library的标题<zbar.h>,示例代码完全正常。

#include <iostream>
#include <Magick++.h>
#include <zbar.h>
#include <highgui.h>
#include <cv.h>

using namespace std;
using namespace zbar;
using namespace cv;

int main (int argc, char **argv){
if(argc < 2) return(1);

// create a reader
ImageScanner scanner;

// configure the reader
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);

// obtain image data
Magick::Image magick(argv[1]);  // read an image file
int width = magick.columns();   // extract dimensions
int height = magick.rows();
Magick::Blob blob;              // extract the raw data
magick.modifyImage();
magick.write(&blob, "GRAY", 8);
const void *raw = blob.data();

// wrap image data
Image image(width, height, "Y800", raw, width * height);

// scan the image for barcodes
int n = scanner.scan(image);

cv::Mat dispImage = imread(argv[1]);

// extract results
for(Image::SymbolIterator symbol = image.symbol_begin();
    symbol != image.symbol_end();
    ++symbol) {
    // do something useful with results
    cout << "decoded " << symbol->get_type_name()
         << " symbol \"" << symbol->get_data() << '"' << endl;
      }
}
// clean up
image.set_data(NULL, 0);

return(0);
}

但是如果我在这个类的标题中创建一个虚拟类并包含zbar.h,我会收到以下错误:

the default argument for parameter 0 of ‘zbar::Exception::Exception(const void*)’ has not yet been parsed line 144, external location: /usr/local/include/zbar/Exception.h C/C++ Problem

#ifndef DUMMY_H
#define DUMMY_H

#include <zbar.h>

class dummy{
public:
    dummy();
};

#endif // DUMMY_H

我甚至试过

extern "C"{
    #include <zbar.h>
}

但它会导致100次template with C linkage错误。

1 个答案:

答案 0 :(得分:2)

根据this documentation,构造函数声明为

Exception(const void * = NULL);

该错误表明尚未声明NULL;意味着没有包含<cstddef>。你应该能够通过在邪恶的标题之前自己包含它来解决它。