+ 3

Difference between default constructor and explicitly defaulted constructor

What is the difference between this class A { protected: A() = default; }; and this class A { protected: A() {} }; This is the code I'm trying to understand. I understand the most parts but why is the default constructor is set to be equal "default" https://github.com/TheCherno/Hazel/blob/master/Hazel/src/Hazel/Core/Input.h

29th Nov 2019, 9:33 AM
Light
Light - avatar
5 Antworten
+ 3
CuRSeD There isn't any difference but if you give your own default constructor then the compiler will not provide the implicit default constructor. Edit: Just like ~ swim ~ mentioned if you try to use both inside the class then it is not a problem until and unless you are assigning one of them to default.
29th Nov 2019, 10:10 AM
Avinesh
Avinesh - avatar
+ 2
CuRSeD The first case means that you want to use the default constructor provided by the compiler. Whereas in the second case you have declared a default constructor of your own.
29th Nov 2019, 9:59 AM
Avinesh
Avinesh - avatar
+ 1
@Avinesh Is there any difference between a default constructor provided by the compiler and a default constructor with an empty body? Is it any different between compiler to compiler or it's just syntax sugaring?
29th Nov 2019, 10:07 AM
Light
Light - avatar