Thread View: comp.std.c++
2 messages
2 total messages
Started by Alexander J. Oss
Fri, 17 Nov 1995 16:41
Deleting Pointers To Const
Author: Alexander J. Oss
Date: Fri, 17 Nov 1995 16:41
Date: Fri, 17 Nov 1995 16:41
33 lines
1534 bytes
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. ]
Re: Deleting Pointers To Const
Author: Fergus Henderson
Date: Thu, 23 Nov 1995 03:05
Date: Thu, 23 Nov 1995 03:05
21 lines
1489 bytes
1489 bytes
"Alexander J. Oss" <alex.oss@films.com> writes: >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). That's right - it's OK to delete pointers to const. It used to be illegal, but the committee changed this at the November meeting last year. >I get an error saying "Cannot convert 'const int *' to 'void *' in function >Holder<int>::~Holder()" using TC++ 4.5 for the following code: Your compiler is out-of-date. Time to get a new one ;-) -- Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3 [ 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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads