template<typename TYPE>
class Scoped< TYPE >
Scoped is convenience class that give block scoping to reference counted Objects. Scoped<TYPE> tries to act like a TYPE *.
As a convenience class you don't have to use it. Some people find it easier to manage the reference counting themselves.
Example: Without Scoped:
{
FileIO *file = FileIO::create();
try
{
if(return early)
{
return;
}
}
catch(...)
{
throw;
}
}
FileIO implements file-based IO.
void init(const char *path, const char *mode)
Initialize with the file path and access mode.
int release(void) const
Decrement the reference count by one.
With Scoped:
{
file->init(path, mode);
if(return early)
return;
}
Scoped is a wrapper class around Object that gives it block scoping.
- Note
- be careful when using this outside of blocked scope.
The = operator increments the count which can lead to memory leaks.
Definition at line 148 of file Object.h.