C++ - when should I use a pointer member in a class

后端 未结 4 2177
庸人自扰
庸人自扰 2020-12-07 17:02

One of the thing that has been confusing for me while learning C++ (and Direct3D, but that some time ago) is when you should use a pointer member in a class. For example, I

4条回答
  •  难免孤独
    2020-12-07 17:36

    Allocate it on the stack if you can, from the free-store if you have to. There is a similar question here, where you will find all the "why's".

    The reason you see lots of pointer usage when it comes to games and stuff is because DirectX is a COM interface, and in honesty, most games programmers from back in the day aren't really C++ programmers, they are C-with-classes programmers, and in C pointer usage is very common.

提交回复
热议问题