I am just starting to get into C ++ (I'm an experienced Python / Java developer, getting into the best parts of OpenCL), and I'm very confused about how objects are passed to functions.
Say I have a simple class:
class Thing { int var; int var2; int var3; void doSomething(); };
Now the "size" of this class is at least 3*sizeof(int) (I'm not sure if the function pointer is saved or not). Now let's say that I have two function signatures:
void doThing1(Thing t); void doThing2(Thing* t);
When I call doThing1 , does copying the whole instance doThing1 cause? When I call doThing2 , is only the stack space sizeof(Thing*) required?
Many "ordinary wisdom" on the Internet told me to try using the signature of the doThing1 function, but at first glance it seems very silly - if it really copies the entire object.
I also assume that if a function is going to modify an object that is on the heap (created with the new keyword), it should look like doThing1 .
Please correct my ignorance. Either my Google searches do not help, or Google does not help.
source share