🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2631

Deleting Pointers To Const

#2631
From: Alexander J. Oss
Date: Fri, 17 Nov 1995 16:41
33 lines
1534 bytes
I've looked in sections 3.7.3.2 and 5.3.5 of the April 28th draft and didn't 
see anything concerning the deletion of pointers to const (except that you 
shouldn't use already-deallocated modifiable lvalues).

I get an error saying "Cannot convert 'const int *' to 'void *' in function 
Holder<int>::~Holder()" using TC++ 4.5 for the following code:

template <class T>
class Holder
{
	const T *object;
public:
	Holder(const T *src) { object = src; }
	virtual ~Holder(); { delete object; }
};

int main()
{
	Holder<int> h(new int(5));
	return(0);
}

When I change the destructor to 

	virtual ~Holder(); { delete const_cast<T *>(object) }

all is well!  Why is that?


[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <NEWTNews.816616683.26228.alex@alexpc.films.com>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: "Alexander J. Oss" <alex.oss@films.com>
Newsgroups: comp.std.c++
Subject: Deleting Pointers To Const
Date: 17 Nov 1995 16:41:29 GMT
Organization: PSI Public Usenet Link
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <NEWTNews.816616683.26228.alex@alexpc.films.com>
NNTP-Posting-Host: taumet.eng.sun.com
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset="US-ASCII"
X-Nntp-Posting-Host: alexpc.films.com
X-Newsreader: NEWTNews & Chameleon -- TCP/IP for MS Windows from NetManage
X-Lines: 29
Content-Length: 669
Originator: clamage@taumet