+ 1

C++ - colon after constructor

What does it mean and do when you have a colon after the constructor? MyClass() : something { }

14th Sep 2021, 8:12 PM
Yahel
Yahel - avatar
1 Odpowiedź
+ 4
That signifies an initialization list. Which can be used in inheritance (call base class) or for initializing member vars before the constructor/body is executed. Here’s a simple ref: https://www.learncpp.com/cpp-tutorial/constructor-member-initializer-lists/
14th Sep 2021, 8:57 PM
DavX
DavX - avatar