Hello there.
New to C++ and the amazing EU5 shenanigans.
I would like to know in which cases would it benefit to create pointers of functions or classes?
Is it the case of perhaps I have a class of moving door, so without pointer the code will be replicated in RAM repeatedly the amount of times equivalent to the objects that use the same class?
First thing to understand is that C++ uses copy semantics by default.
int a = 2;
int b = a;
assert(b == 2);
b = 10;
assert(a == 2);
assert(b == 10);
- Demo
Here b
is initially a copy of a'
s value so modifying b
has no effect on a
's value.
For primitive types this is fast and efficient but for larger types that might not be the case and could be costly if all you want to do is look at its value.
Secondly what if you want to modify an existing object? You have an actor in the level, you want to operate on that specific actor and not a copy of it (which would mean any modification of that copy goes unseen) so you would need to use pointers or references in order to do that.
* Also due to the way they work you would be using pointers for all UObject’s.
to be clear, you have not encountered any yet, you have only seen functions that have returned a pointer to some type.
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.