I know that when you call a function this way :
foo(MyClass a)
The object a is being passed by value meaning it’s being copied.
My question is how is it being copied?
say my class don’t have a copy constructor, so if it is passed using shallow copy than
the object may change inside the function?
Compiler automatically generates the code for the copy constructor and performs member wise copy. The copy constructor which compiler calls does member wise copy which is indeed shallow copy.
It is inadvisable to pass an object by value if a pointer in your class exists. Even if a pointer does not exist, but a dozen other data members exist, they would require a lot of time to get copied.Pass it by reference, and make it
constif you dont want its value to be changed.