The objects I am dealing with are quite large, and often will be created in seperate functions. If you are supposed to use pointers for big objects, this brings back the problem of them going out of scope when the object-creating function returns.
The objects I am dealing with are quite large, and often will be created in seperate functions. If you are supposed to use pointers for big objects, this brings back the problem of them going out of scope when the object-creating function returns.
When the object-creating function returns, the memory dynamically allocated by new will only be deallocated manually. So it works fine, you just need to handle memory management yourself. If for instance you didn't call delete, your program would probably still work, but with a lot of memory leaks. Instead of a pointer, use a smart pointer, and you can use it the same way as Java without any issues (object = create_object()). Most people will recommend you instead allocate an object, and pass it by reference to the object-creating function for initialization (create_object(object)). You get the same result, without pointers, and the function user can handle memory themselves. You can then omit the return value, or use a status value.
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101