Hey,
I'm a Game Developer and saw a lot of Game Engine Code and Company Code(C++)
and I'm still not sure about References, Pointers and Smart Pointers.
I have following Problems:
1)
I've read a lot of books since I started with C++(years ago) and it was always said to use References over Pointers, but when I look through the code of Engines or Frameworks I nearly never see any Reference , but normal Pointers(parameters, return values, etc...). For an example,in engines i nearly always get a pointer to Object which is inside my Game(e.g. a Actor). I always just return Objects as Reference (e.g Object& GetObject(){return obj;} ) Can anyone help me here?
2)
Before I started with C++, I've learned Java & C#, where you created every Object with Object obj = new Object(); In C++ you shouldn't just use new, but you should use a smart pointer or no pointer at all.
In other forums, people told me that I actually nearly never need to create Objects with new at all in C++, but I'm not quite sure about this answer. When should I actually use smart pointers, because unit now everything worked without them, even without any dynamically created object(new), but this can't be the right way to put everything on the stack.(Performance,other improvements?)
3)
I also see a lot of Lists/Arrays in Engines with pointers,
e.g.
Array<Actor*> .......
But I always create them without pointers, Array<Object> .
And as parameter and getter I would also just use them with references:
1 2 3
|
Array<Object>& GetArray(){return myArray}...
void function(Array<Object>& myArray)
|
(This is actually an question about lists/vectors/arrays in general and if there performance issues with the way i'm using them)
Can anyone help me?