Re: Getting error while making delete operator private
On Aug 13, 1:14 pm, Ron Natalie <r...@spamcop.net> wrote:
I tried following one:
class RefCountImpl
{
private:
//data members
protected:
void operator delete(void*);
public:
//methods
};
if i have above class implementation.Then in VC++6.0 it works. You can
allocate memory using new but you cannot delete that pointer in your
clilent code. You have to use some method provided by above class to
release the pointer.
Same thing doesnt work in VC++.NET. It clearly throws error that
making delete private cause memory leakage. May be VC++.NET compiler
become more stirct about this. :(.....
First off, that is not the delete operator (despite it's unfortunate
name) it is the memory deallocation function.
Yes, but access control for the delete operator is done on the
memory deallocation function which is associated with it.
In this case, of course, what's bothering him is that the access
control for the new operator also checks the memory deallocation
function (because the new operator must call the memory
deallocation function if the constructor exits via an
exception).
Compilers are free to
issue whatever diagnostics they want over the required ones.
In this case, the compiler is required to issue the diagnostic.
=A75.3.4:
If the new-expression creates an object or an array of
objects of class type, access and ambiguity control are
done for the allocation function, the deallocation
function (12.5), and the constructor (12.1). If the new
expression creates an array of objects of class type,
access and ambiguity control are done for the destructor
(12.4).
Why did you do this?
As he said, he didn't want any one else to delete the class.
(Think about it for a moment. For most classes that you
allocate dynamically, anything but a delete this would be an
error.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34