is there a way to have a default Object for parameters in C++ functions? I tried
void func(SomeClass param = new SomeClass(4));
and it worked. However how would I am I supposed to know wheter I have to free the allocated memory in the end? I would like to do the same without pointers, just an Object on the stack. is that possible?
You almost had it but you don’t need the
newkeyword.This method has the advantage over using
newin that it will be automatically deleted at the end of a call so no memory management is needed.An alternative is to use shared pointers.