diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index fa5b8fd..ba30176 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -157,7 +157,7 @@ QrSegment QrSegment::makeEci(long assignVal) { QrSegment::QrSegment(const Mode &md, int numCh, const std::vector &dt) : - mode(md), + mode(&md), numChars(numCh), data(dt) { if (numCh < 0) @@ -166,7 +166,7 @@ QrSegment::QrSegment(const Mode &md, int numCh, const std::vector &dt) : QrSegment::QrSegment(const Mode &md, int numCh, std::vector &&dt) : - mode(md), + mode(&md), numChars(numCh), data(std::move(dt)) { if (numCh < 0) @@ -177,7 +177,7 @@ QrSegment::QrSegment(const Mode &md, int numCh, std::vector &&dt) : int QrSegment::getTotalBits(const vector &segs, int version) { int result = 0; for (const QrSegment &seg : segs) { - int ccbits = seg.mode.numCharCountBits(version); + int ccbits = seg.mode->numCharCountBits(version); if (seg.numChars >= (1L << ccbits)) return -1; // The segment's length doesn't fit the field's bit width if (4 + ccbits > INT_MAX - result) @@ -210,8 +210,8 @@ bool QrSegment::isNumeric(const char *text) { } -QrSegment::Mode QrSegment::getMode() const { - return mode; +const QrSegment::Mode &QrSegment::getMode() const { + return *mode; } diff --git a/cpp/QrCode.hpp b/cpp/QrCode.hpp index 06d661a..9e7f7fc 100644 --- a/cpp/QrCode.hpp +++ b/cpp/QrCode.hpp @@ -151,7 +151,7 @@ class QrSegment final { /*---- Instance fields ----*/ /* The mode indicator of this segment. Accessed through getMode(). */ - private: Mode mode; + private: const Mode *mode; /* The length of this segment's unencoded data. Measured in characters for * numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. @@ -186,7 +186,7 @@ class QrSegment final { /* * Returns the mode field of this segment. */ - public: Mode getMode() const; + public: const Mode &getMode() const; /*