4 ms·
Yep, it's full of raw pointers. Smart pointers were already available in 2014.
by pajko 4y ago
Yep, it's full of raw pointers. Smart pointers were already available in 2014.
- pjmlp 4y agoTo be more precise, they were already part of C++ libraries when C++98 was still in progress, e.g. ComPtr in MFC.
- 1f60c 4y agoThe author explains why in the first chapter^: > The goal of this book is not to teach you C++. The samples are kept as simple as possible and don’t represent good C++ style or usage. Read the code samples for the idea being expressed, not the code expressing it. > > In particular, the code is not written in “modern” — C++11 or newer — style. It does not use the standard library and rarely uses templates. This makes for “bad” C++ code, but I hope that by keeping it stripped down, it will be more approachable to people coming from C, Objective-C, Java, and other languages. ^ https://gameprogrammingpatterns.com/introduction.html#about-the-sample-code https://gameprogrammingpatterns.com/introduction.html#about-...
- GuB-42 4y agoSo what? Smart pointers are not a superior alternative to raw pointers. They are a memory management device that you may or may not want to use. For example a pattern that I think is common in low level game programming is to allocate a big chunk of memory containing a many objects and deallocating them all at once when you are done with them, let's say a level with its maps, textures, entities, etc... It doesn't really make sense to pass individual objects (ex: a single texture) using smart pointers because you can't delete them individually, in fact, unless you have overloaded the delete operator, it will crash if you do. In fact, if you never use raw pointers, I think that you are better off using another language than C++ if you can. Manual memory management is a big part of what gives C and C++ its performance (at a cost). If you don't do that, there are languages with well optimized garbage collectors that will outperform you.