Solved C++ % " ?
-
This (https://code.woboq.org/qt5/qtwebengine/src/core/web_engine_library_info.cpp.html):
149 const QString processBinary = QLatin1String(QTWEBENGINEPROCESS_NAME) % QLatin1String(".exe");
Non-C++-er here. Last time I looked
%
operator was modulus, and if you wanted string concatenation it was+
. So what's going on here?? Don't tell me (I refuse to just look it up, and I don't even know for sure it works that way)QString
has defined a%
operator to replace modulus with something for strings... :( -
@JonB short answer: yes,% is equal + in QString.
Long answer: google for QStringBuilder.
-
-
Oh dear, oh dear. Thanks.
-
They didn't overload
operator ,
so everything is under control :) -
@Konstantin-Tokarev
LOL! Wait!! You can overload the C comma operator? OMG! -
-
@kshegunov
Haven't seen you in a while!I was thinking earlier: why couldn't/didn't C++ allow defining your own operators then? I have used languages where you can. By the time Qt is having
QString
override an operator to add some convenient behaviour, it's plain confusing that it picks an existing "modulus" symbol to do it :( If you're going to change the meaning so much, you only really need to be able to specify the precedence and you might as well be free to pick your own operator characters.Going back to the
,
operator. I didn't realise it was a true operator, that means you have to be consistent about the types on each side, I didn't think the left-hand side mattered, I thought it just returned the right-hand side. -
@kshegunov
Haven't seen you in a while!many-a-work.
I was thinking earlier: why couldn't/didn't C++ allow defining your own operators then?
It could've, I imagine it's a conscious choice not to make it even more confusing.
Going back to the
,
operator. I didn't realise it was a true operatorYes, albeit a low-priority one.
-
@Konstantin-Tokarev
LOL! Wait!! You can overload the C comma operator? OMG!There is hardly a thing one can't change/overload in c++.
But you do, the operation should be somewhat related to the original. Otherwise you'll end up with confusion and lost development time.I'm looking at you boost
-
@J.Hilk
LOL, I don't know about Boost. But how's about the subject of this post: how is thisQString %
operator related to original modulus? -
Hope you cannot overload ';' That would probably cause the ultimate confusion.
-
@koahnig
;
is not an operator. I believe it is a "statement separator" (whereas Pascal had it as a "statement terminator"... or is it the other way round?). -
Thanks for clarification, I am so happy about that ;)
However, with the ancient FORTRAN they discussed a COME FROM statement
Therefore, you never know what somebody will come up with. At least FORTRAN did not require a "statement separator" nor a "statement terminator". The logical end of aline was the end of the punching card after 80 chars respectively you had to subtract 8 digits for the line number. -
-
Though you should better define
QT_USE_QSTRINGBUILDER
and simply use+
everywhere instead of%
-
@Konstantin-Tokarev said in C++ % " ?:
Though you should better define
QT_USE_QSTRINGBUILDER
and simply use+
everywhere instead of%
Ooohhh, the plot thickens...!
-
@JonB Qt has ome confusing operaters as well.
for example take QVectors +=
QVector<T> QVector::operator+(const QVector<T> &other) const
I would asume this to be Vector addtion
QVector v1{a,b,c}; QVector v2{d,e,f}; //What one would expect v1 += v2; -> {a+d, b+e, c+f} //what one gets v1 +=v2; _> {a,b,c,d,e,f}
I mean, this technically makes sense. QVector is to generic to have this operation, thats why there is QVector2D, 3D, 4D etc
It still confused me the first time I used it. I did not expect += to be equal to .append() or <<;
In this paticular example I have would prefere a missing += operator :-).
-
@J.Hilk To be honest I would be rather confused if it would do
v1 += v2; -> {a+d, b+e, c+f}
A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)
-
@J.Hilk To be honest I would be rather confused if it would do
v1 += v2; -> {a+d, b+e, c+f}
A vector is not a number or something, it is a container. Or is it because it is called "vector" and you expect it to behave like a vector in math? :-)
That is debatable and apparently dependent on your background. The foprm you find confusing would be the most logical version for me.