Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Find what you need - explore our website and developer resources
28 June 2022
C++ has a keyword called explicit, but why are there no implicit keywords?
Further how can it possibly be needed in the context of QObjects? And is there any tooling available that can help me ensure that it is everywhere, or that I at least have thought carefully about it, in those places where it should be?
Get these answers and many more in this episode where I talk to Peppe.
0:00 Introduction
1:46 Implicit conversion in a string class
5:00 implicit conversion going wrong
8:00 the explicit keywords to the rescue
9:29 Named constructors
11:00 Why is explicit a problem in the contest of QObject sub-classes?
19:44 Should I always use explicit?
23:33 Q_IMPLICIT
24:33 explicit(false)
25:48 Implementation of Q_IMPLICIT
26:39 clang-tidy support
31:16 When should I not use explicit - QPoint
34:13 Rule of thumb when implicit is OK
Links:
Episode on running clang-tidy from command line: https://youtu.be/c0ie0xww7SA?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
The clang-tidy check: https://clang.llvm.org/extra/clang-tidy/checks/google/explicit-constructor.html
Clang-tidy suppression not working from macros: https://github.com/llvm/llvm-project/issues/55134
Clang.-tidy bug: explicit(false) still generates a warning: https://github.com/llvm/llvm-project/issues/53115
All QML tips and tricks videos : https://www.youtube.com/playlist?list=PL6CJYn40gN6jWHP5krsQrVGyYtKh3A3be
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Learn Modern C++
Our hands-on Modern C++ training courses are designed to quickly familiarize newcomers with the language. They also update professional C++ developers on the latest changes in the language and standard library introduced in recent C++ editions.
Learn more