0

I was wondering if there is any difference between explicitly declaring a trivial constructor and setting it to default or omitting the constructor completely.

Example:

struct someint { int n; someint() : n(0) {} }; class example1 { public: someint n; }; class example2 { public: someint n; example2() = default; }; 

Is there any difference between example1 and example2? Or is it just a style difference?

3
  • A user provided constructor is by definition never trivial even if it does nothing. Commented Aug 29, 2022 at 13:11
  • Yes, there are some nuanced differences when it comes to more exotic parts of C++, such as the various rules that define when other default constructors and/or operators get automatically deleted, or not. Commented Aug 29, 2022 at 13:11
  • see here: stackoverflow.com/questions/21164641/…, or here: stackoverflow.com/questions/20828907/… Commented Aug 29, 2022 at 13:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.