I've not seen this specific oddity of C++ before and it's causing me a bit of confusion.
I have the following class:
class KeyValuesParser
{
public:
explicit KeyValuesParser(const QByteArray &input);
QJsonDocument toJsonDocument(QString* errorString = nullptr);
// ...
};
And I'm trying to use it like so in a Qt unit test:
const char* testData = "...";
KeyValuesParser parser(QByteArray(testData));
QJsonDocument doc = parser.toJsonDocument();
This gives the following compile error:
Member reference base type 'KeyValuesParser(QByteArray)' is not a structure or union.
However, if I create the byte array on the stack and then pass it in, instead of passing in a temporary, everything compiles fine:
const char* testData = "...";
QByteArray testByteArray(testData)
KeyValuesParser parser(testByteArray);
QJsonDocument doc = parser.toJsonDocument();
I thought this might have been some weird black magic that required the explicit
keyword (which is why I added it), but that didn't make any difference. Can anyone explain what's going on here?
EDIT: I've been referred to another question as being a duplicate and I think it almost is, but there's some most-vexing-parse confusion on this question that I think merits the extra discussion.