File: delete.yo

package info (click to toggle)
c%2B%2B-annotations 10.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,536 kB
  • ctags: 3,247
  • sloc: cpp: 19,157; makefile: 1,521; ansic: 165; sh: 128; perl: 90
file content (44 lines) | stat: -rw-r--r-- 1,736 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
The ti(delete) operator may also be overloaded. In fact it's good practice to
overload ti(operator delete) whenever tt(operator new) is also overloaded.

tt(Operator delete) must define a ti(void *) parameter.  A second overloaded
version defining a second parameter of type tt(size_t) is related to
overloading tt(operator new[]) and is discussed in section
ref(NEWDELETEARRAY).

Overloaded tt(operator delete) members return tt(void).

    The `home-made' tt(operator delete) is called when deleting a dynamically
allocated object after executing the destructor of the associated
class. So, the statement
        verb(
    delete ptr;
        )
    with tt(ptr) being a pointer to an object of the class tt(String) for
which the operator tt(delete) was overloaded, is a shorthand for the following
statements:
        verb(
    ptr->~String(); // call the class's destructor

                    // and do things with the memory pointed to by ptr
    String::operator delete(ptr);
        )
    The overloaded tt(operator delete) may do whatever it wants to do with the
memory pointed to by tt(ptr). It could, e.g., simply delete it. If that would
be the preferred thing to do, then the default
tt(delete) operator can be called using the ti(::)
 i(scope resolution operator). For example:
        verb(
    void String::operator delete(void *ptr)
    {
        // any operation considered necessary, then, maybe:
        ::delete ptr;
    }
        )
    To declare the above overloaded tt(operator delete) simply add the
following line to the class's interface:
        verb(
    void operator delete(void *ptr);
        )
    Like tt(operator new operator delete) is a static member function
(see also chapter ref(StaticDataFun)).