S
Soumen
For one of my project, I want to use auto_ptr. But I'm facing few
issues.
1. Say I've Controller class. I don't want to allow user to create
object of this class unless all arguments
are valid. So I've made the constructor private and given one
static method to create an object of this
class. Since one of senior members in the team doesn't like
throwing exception, I've made this static
method to return NULL pointer when arguments are not valid. But
that stops using auto_ptr since it
cannot accept NULL, I guess. Is there any better way to do this?
2. Now, I've a Cache class in which few members are auto_ptr. Those
basically some pointer to few
STL type map or set etc. Now users of this Cache class needs read
access to these data. Is returning
a const reference a good idea? Returning the member itself will
cause transfer of ownership and I guess
returning a pointer is not a good idea since the user has control
of destroying the object pointed by it.
Let me know your views. This may be trivial design issues to most of
you. But I'm not an expert in
design issues. Thanks in advance to all your help.
Regards,
~ Soumen
issues.
1. Say I've Controller class. I don't want to allow user to create
object of this class unless all arguments
are valid. So I've made the constructor private and given one
static method to create an object of this
class. Since one of senior members in the team doesn't like
throwing exception, I've made this static
method to return NULL pointer when arguments are not valid. But
that stops using auto_ptr since it
cannot accept NULL, I guess. Is there any better way to do this?
2. Now, I've a Cache class in which few members are auto_ptr. Those
basically some pointer to few
STL type map or set etc. Now users of this Cache class needs read
access to these data. Is returning
a const reference a good idea? Returning the member itself will
cause transfer of ownership and I guess
returning a pointer is not a good idea since the user has control
of destroying the object pointed by it.
Let me know your views. This may be trivial design issues to most of
you. But I'm not an expert in
design issues. Thanks in advance to all your help.
Regards,
~ Soumen