🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Is it ok to do this in C ++? Use of "class".

Started by
12 comments, last by Dawoodoz 4 years, 6 months ago

The same pattern is used in C with the "struct" keyword, which is equivalent to "class" but public by default. Quadratic growth of compilation times in C++ is one of the most difficult problems in large C++ projects because headers weren't made for complex class inheritance, so the solution is quite elegant by not exposing any private class variables in headers. The only drawback is that value types cannot use this pattern for stack allocation by not knowing the object size until linking, which explains why only "Math.h" is included from the project.

Advertisement

This a popular thing, called PIMPL, there are ways to do it on the stack with large unaligned storage and static_asserts.
Probably there is something a bit more clever these days.

ongamex92 said:

This a popular thing, called PIMPL, there are ways to do it on the stack with large unaligned storage and static_asserts.
Probably there is something a bit more clever these days.

C++ "modules" are supposed to partially replace headers for non-syntax stuff by compiling on top of previously compiled documents where the size has already been calculated. This however forces a layered approach that doesn't work with the visitor pattern and cyclic dependencies.
https://vector-of-bool.github.io/2019/03/10/modules-1.html

This topic is closed to new replies.

Advertisement