main中的标头包含.cpp有效,但在类中抛出错误
header include in main.cpp works, but throws error in class
我在这里问过这个问题。但问题似乎是其他东西,所以在这里重新发布..
我在main中包含来自Zbar库的标头<zbar.h>
.cpp示例代码运行良好。
#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
错误。
根据此文档,构造函数声明为
Exception(const void * = NULL);
该错误表明尚未声明NULL
;这意味着没有包含<cstddef>
。您应该能够通过在邪恶标头之前包含自己来修复它。
相关文章:
- 分段错误当我试图运行程序时出错
- .h 和.cpp文件分离时出错,但仅使用 .h 文件时没有错误.我做错了什么?
- 创建 OpenCV 非自由版本 v4.3 时出错,可折叠.cpp错误 C2039、2605
- 制作时出错,C++"db.c:2127:错误:在"||"标记之前应使用";"
- C++语法错误,编译器不会警告或 int v = func(&v) 出错;
- 在VS2015中访问类成员时运行时错误,但在Linux上未访问时出错
- 如何更改路径以修复错误"./main:加载共享库 libmkl_core.so 时出错?
- 为什么在定义类之前声明类的对象会在友元类中给出错误,而在友元函数中不会出错
- 安装 mply 库时出错.致命错误:gsl/gsl_sf.h:没有这样的文件或目录
- Rcpp/C++/R:比较日期时间矢量与日期时间时出错(错误:"运算符>"的不明确重载)
- 编译特征程序时出错:错误:'seq'不是'Eigen'的成员
- 可能的 GCC 链接器错误会导致将弱符号和局部符号链接在一起时出错
- 非标准语法;使用 '&' 创建指向成员的指针错误,将成员函数分配给向量时出错
- 运算符重载时出错(错误:"运算符<<不匹配(操作数类型为"std::basic_ostream<char>"和"const char [2]")
- 编译类 C++ 中的线程时出错(错误 xthread)
- 加载GLEW库时出错(错误LNK2001)
- 通过函数指针调用函数时出错(错误C2064)
- 编译core.obj时出错:错误LNK2001:未解析的外部符号_harmony_core_init
- 链接c++静态库与android ndk时出错(错误:无法识别文件格式)
- 使用GCC编译游戏时出错.(错误:将"Screen"的含义从"class Screen&q