Re: delete the dynamically allocated memory twice causes error
"tom" <pxknet@gmail.com> wrote in message
news:1185321798.942351.98490@g12g2000prg.googlegroups.com...
On Jul 25, 6:43 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
Alf P. Steinbach wrote:
* tom:
why delete the dynamically allocated memory twice causes an error,
see the code below:
int _tmain(int argc, _TCHAR* argv[])
{
int *pi = new int(12);
cout<<*pi;
delete pi;
delete pi;
}
There's no such thing as _tmain in standard C++. There's no such
thing as _TCHAR in standard C++. Your code does not compile. This
group is for discussing standard C++. Please fix your example, and
repost.
Chill, Alf. For all we know, _tmain is a function OP wrote himself.
And what _TCHAR is *is* quite irrelevant to the question asked. Of
course "_TCHAR" is a reserved identifier which makes it prohibited
in the program outside of the library implementation. And 'cout' is
not really defined here. But, hey, so what? To ask a question like
that the code doesn't even have to be complete. It should be enough
to write
int *pi = new int(12);
// use pi somehow
delete pi;
delete pi;
to get a normal answer to the question. Perhaps you should get off
your high moderator's horse once in a while, eh?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide quoted
text -
- Show quoted text -
I'm new here. And that's why I need to make a post here and ask
questions.
And my question is not relevant to the name of the function and type
of the variable. And
as far as I know the language could have a standard, but there won't
be a compiler 100% follow the standard.
Correct me if I'm wrong.
I wouldn't worry about it too much Tom. Some users get upset at a few things
and refuse to answer questions if a post contains them. Such as:
void main()
main MUST return an int.
int _tmain(int argc, _TCHAR* argv[])
this is how windows specific code handles the mainline in code. Even though
everyone knows there IS a main() somewhere that calls _tmain() some people
get upset because it's not called main.
C/C++
The langauge is not called C/C++ it's called C or C++, pick one
Basically, when someone responds with replies like this without answering
the question, I ignore them. Although you should get into the habit of
renaming _tmain to main when you post, etc... just so you don't have to
listen to people like this bitch.