W
WaterWalk
Hello. The question about "deleting this inside the class's member
function" is discussed many times in this group and in the "C++
FAQs". But I still have two more questions.
1. Take the following class as an example:
class Test
{
public:
static void print_message(char *s) { printf("%s\n", s); }
void delete_me()
{
delete this;
print_message("deleted!"); // safe and legal?
}
};
The question is: after "delete this" inside a member function, is it
legal to call a static member function of that class? And what does
the standard says about this?
2. Where in the standard can I find information about the "delete
this" thing? When viewing discussion about "delete this", I often
found people saying "it is legal" or "it conforms to the standard".
But after some quick reading in C++ standard 98, I still can't find
any clue. So I'm just curious where the relevant information can be
found in the standard.
function" is discussed many times in this group and in the "C++
FAQs". But I still have two more questions.
1. Take the following class as an example:
class Test
{
public:
static void print_message(char *s) { printf("%s\n", s); }
void delete_me()
{
delete this;
print_message("deleted!"); // safe and legal?
}
};
The question is: after "delete this" inside a member function, is it
legal to call a static member function of that class? And what does
the standard says about this?
2. Where in the standard can I find information about the "delete
this" thing? When viewing discussion about "delete this", I often
found people saying "it is legal" or "it conforms to the standard".
But after some quick reading in C++ standard 98, I still can't find
any clue. So I'm just curious where the relevant information can be
found in the standard.