When creating a class that allocates resources, which operators should be overloaded? Consider this code segment, for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class ResourceAllocator
{
public:
ResourceAllocator( void );
~ResourceAllocator( void );
protected:
// _pAllocator: Used to allocate the resources for an undefined
// reason. This is an example code segment after all.
int *_pAllocator;
public:
intoperator [ ] ( constunsignedint iIndex );
// Return a boolean value to clearly indicate a successful/unsuccessful
// operation assignment.
int &operator = ( const ResourceAllocator &rAllocator );
};
In the above code segment, would it be beneficial to overload the sub-script, and equals assignment operators rather than use methods? Also, what other operator( s ) should be overloaded in a class such as this( if any )?
Thank you for your input, WebJose. I've modified the code.
webJose wrote:
For an allocator, I would think it has an Allocate() method and a Free() method. I don't see myself mapping those operations to operators.
It does seem cleaner to use methods for allocation and deletion. For now, I think I'll stick with the basic operators such as sub-script, and equals assignment.