Destructor for const object
From: Virendra Verma (virenbeena_at_hotmail.com)
Date: 04/12/04
- Next message: Sandra: "Birthday Problem"
- Previous message: red floyd: "Re: spawnvp does not work"
- Next in thread: Kevin Goodsell: "Re: Destructor for const object"
- Reply: Kevin Goodsell: "Re: Destructor for const object"
- Reply: tom_usenet: "Re: Destructor for const object"
- Reply: Nick Hounsome: "Re: Destructor for const object"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 12 Apr 2004 08:35:33 -0700
This sounds weird, but I am looking for separate behaviors for
destruction of a const and non-const object.
I am trying to develop a smart/auto pointer class for writing objects
to disk implicitly. The destructor of this class saves the object to
the disk if it is dirty. The problem comes in the following scenario
when a function returns an uncommitted pointer class because same
copies will be committed as two separate objects on disk. For example,
DbPtr< T > some_function( )
{
.....
DbPtr<T> pN; // uncommitted copy
return pN; // pN will be committed in the destructor but the
returned
// copy is not. I could define an assignment operator
// for DbPtr<T> as below but the commit operation
// on const object has problems as it has to modifies
// object
}
tempalte<class T>
class DbPtr : public some_base {
public:
~DbPtr<T>( ) { commit(); } // I need to recognize here if I am
destroying
// a const object to bypass commit.
void commit( );
void operator=( const DbPtr<T>& rP ) { *this = rP; }
void operator=( DbPtr<T>& rP ) { rP.commit(); *this = rP; }
}
Thanks in advance.
-- Virendr
- Next message: Sandra: "Birthday Problem"
- Previous message: red floyd: "Re: spawnvp does not work"
- Next in thread: Kevin Goodsell: "Re: Destructor for const object"
- Reply: Kevin Goodsell: "Re: Destructor for const object"
- Reply: tom_usenet: "Re: Destructor for const object"
- Reply: Nick Hounsome: "Re: Destructor for const object"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]