Hello people,

I am using zbar library to detect barcode. I am able to compile and run their sample code in main.cpp
Now if I make a class and include <zbar.h> in the header of that class, I get the following error :

/usr/local/include/zbar/Exception.h:144: error: the default argument for parameter 0 of 'zbar::Exception::Exception(const void*)' has not yet been parsed

Why is this happening?

This is the code that works.

#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);
}

Now I make a dummy class.

#ifndef DUMMY_H
#define DUMMY_H

#include <zbar.h>

class dummy{
public:
    dummy();
};

#endif // DUMMY_H

This gives me an error :
/usr/local/include/zbar/Exception.h:43: error: 'NULL' was not declared in this scope
/usr/local/include/zbar/Exception.h:144: error: the default argument for parameter 0 of 'zbar::Exception::Exception(const void*)' has not yet been parsed

Apparently zbar.h does not define NULL. Did you try including iostream (or some other header file that defines NULL) before zbar.h in dummy.h?

I tried including <cstddef>, <stddef.h> <stdlib.h>, <cstdlib>, <iostream>... But the problem persists!

But why is it that it works in main.cpp but not in dummy.h? If NULL is undefined, it shouldn't have worked even in main.cpp, right?

I'm sorry it workeed!!! But again, why is it that it works in main.cpp but not in dummy.h? If NULL is undefined, it shouldn't have worked even in main.cpp, right?

just for test these:

#ifndef DUMMY_H
#define DUMMY_H

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

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

class dummy{
public:
    dummy();
};

#endif // DUMMY_H

tell me if you don't get any errors

"But again, why is it that it works in main.cpp but not in dummy.h? If NULL is undefined, it shouldn't have worked even in main.cpp, right?"
i think it's the dependency libraries. like i did with code.
maybe the zbar.h depends on other header files.

@Cambalinho : the code worked... the main.cpp already had iostream included before zbar.h, which wasn't the case in dummy.h.
Thanks!

This article has been dead for over six months. Start a new discussion instead.