1

I try to write function with constexpr

constexpr QString c(const QString &columnName);

but it output issue:

enclosing class of constexpr non-static member function 'QString DatabaseHandler::c(const QString&) const' is not a literal type constexpr QString c(const QString &columnName);

I very bad know C++ 11 yet so cannot undestand this bug. What does it mean?
P.S. If I add static then it also output issue Invalid return type 'QString'.

1 Answer 1

7

constexpr functions require that their input arguments and their return type are literal types, and therefore must have at least one constexpr constructor. Qstring (i.e, the return type) does not, thus you get a compiler error.

Sign up to request clarification or add additional context in comments.

4 Comments

I didn't know... Thanks! I read now that Qt 4.8 supports C++ 11, so I think that it must have this constructor. Or I don't understand something?
A reference type is a literal type. In the OP's case, it's the return type that is not of a literal type, isn't it?
I found now QStringLiteral define but I cannot understand how to use it
@PiotrSkotnicki Yeah, I corrected thanx, you rock ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.