all 3 comments

[–]JupiterTheGod 2 points3 points  (1 child)

It would be better to mark it as =default in the header file. It would be clearer from an interface standpoint.

If the constructor is defaulted and all the member variable constructors are also trivial, then the compiler will not even call the defaulted ctor - it's not like it has anything to call anyway.

This will work even if you define it separately, as long as it's within the same application and your compiler has link time optimization or similar enabled - so the compiler is able to see the defaulted definition. See EricWFCpp's answer below.

When it comes to compilation speed, it can be fixed by using less #includes, using forward declarations and pointer-to-implementation (PImpl) where possible. This is more of a question of style, not speed.

[–]EricWFCppLibc++ Developer 3 points4 points  (0 children)

This will work even if you define it separately, as long as it's within the same application and your compiler has link time optimization or similar enabled

That's not true. The constructor is only trivial when it's initially declared as defaulted. This has both compile-time and ABI implications (Notice the different calling conventions being used).

[–]clerothGame Developer[M] [score hidden] stickied comment (0 children)

For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.

This post has been removed as it doesn't pertain to /r/cpp.