diff --git a/cpp/qrcodegen.cpp b/cpp/qrcodegen.cpp index 0957b79..40102d5 100644 --- a/cpp/qrcodegen.cpp +++ b/cpp/qrcodegen.cpp @@ -359,6 +359,18 @@ QrCode::QrCode(int ver, Ecc ecl, const vector &dataCodewords, int msk) } +QrCode::QrCode() : + version(MIN_VERSION), + size(0), + mask(0), + errorCorrectionLevel(Ecc::LOW) { +} + + +bool QrCode::isValid() const { + return size > 0; +} + int QrCode::getVersion() const { return version; } diff --git a/cpp/qrcodegen.hpp b/cpp/qrcodegen.hpp index 9448982..8b9090d 100644 --- a/cpp/qrcodegen.hpp +++ b/cpp/qrcodegen.hpp @@ -333,9 +333,20 @@ class QrCode final { */ public: QrCode(int ver, Ecc ecl, const std::vector &dataCodewords, int msk); - + /* + * Default constructor for an uninitialized (empty) QrCode. Useful for when a + * QrCode instance is needed prior to being assigned to. Subsequent calls + * to isValid will return false until a copy assignment is made. + */ + public: QrCode(); /*---- Public instance methods ----*/ + + /* + * returns false if constructed with the default constructor and not updated with a valid + * assignment + */ + public: bool isValid() const; /* * Returns this QR Code's version, in the range [1, 40].