Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,267 of 33,346    |
|    Francis Glassborow to Asger Joergensen    |
|    Re: Explicit destructor call - problem w    |
|    09 May 12 15:04:59    |
      From: francis.glassborow@btinternet.com              On 09/05/2012 21:15, Asger Joergensen wrote:       > Hi PiotrN       >       > PiotrN wrote:       >       >> Hello,       >>       >> Two questions:       >> 1) Why I cannot call destructor for builtin types like int:       >> int a;       >> int* p = new int[7];       >> p->~int();       >       > You never call the destructor directly you use delete instead:              Untrue. You use a destructor call whenever you want to retain the       underlying memory       >       > int* p = new int[7];       >       > ....do some work       >       > delete[] p;              All that is fine until you are using a placement new in a context where       calling delete is wrong. For example, when using a memory pool.                     The real problem with the above is that if you are using a dtor call you       cannot apply it to p because p is a pointer to an array.              However there is also the problem that you cannot use the dtor syntax on       a buitin type by its formal name only when using an alias either       provided through a typedef or by a template parameter.              I think the argument is that if you know the name you know it is trivial       so nothing needs to be done. That you can use the syntax on an alias       provided through a typedef is an artefact of way we provided template       type names. It is also not irrational because if you want to change some       code by replacing a usage of int by a usage of some other type you would       want it to continue to work. E.g.              I write all by code using:              typedef int year;              and at a later stage decide I want to provide a real year type (called       my_year_type which has a non-trivial dtor then I can simply replace the       typedef with:              typedef my_year_type year;              and the code should continue to work.              Another way of looking at this is that an int is an int and there is no       way you can make it anything else but and INT may stop being an int and       become anything else the programmer wants it to be which may not be a       type with a trivial dtor.                     --        [ See http://www.gotw.ca/resources/clcm.htm for info about ]        [ comp.lang.c++.moderated. First time posters: Do this! ]              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca