|
Boost : |
From: Pavel Vozenilek (pavel_vozenilek_at_[hidden])
Date: 2004-03-08 19:55:06
"David Abrahams" <dave_at_[hidden]> wrote
> I can't understand this claim. If the counter works properly, then it
> will stay valid.
>
This example was too simplified (and thus not to the point).
More complex one:
-----------------------
struct my_class
{
void* database_handle;
my_class() { database_handle = allocate_handle(); }
~my_class() { destroy_db_handle(database_handle); }
my_class& operator=(const my_class& other) {
// no copy of database handle, not needed,
// not useful here
}
my_class(const my_class& other) {
database_handle = allocate_handle(); // needs unique db connection
}
};
circular_buffer<my_class> buffer(1);
{
my_class a;
buffer.push_back(a); // 2 handles after function returns
...
}
{
my_class b;
buffer.push_back(b); // desctructor not called, handle lost
...
}
-----------------
To deal with lost resources you would need to modify
operator=() to take ownership of all rhs resources.
But in this case following will fail:
my_class a;
my_class b;
a = b;
// b is stripped of its handle now, cannot be used
/Pavel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk