Re: Is it an undefined behavior in C++ Standard?
From: aka (akademecia_at_hotmail.com)
Date: 03/13/05
- Previous message: Ioannis Vranos: "Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)"
- In reply to: Peter Koch Larsen: "Re: Is it an undefined behavior in C++ Standard?"
- Next in thread: Victor Bazarov: "Re: Is it an undefined behavior in C++ Standard?"
- Reply: Victor Bazarov: "Re: Is it an undefined behavior in C++ Standard?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 13 Mar 2005 16:03:11 +0800
I'm learning Visual C++ 2005. I want to know how it implement ISO C++
standard, such as undefined behavior.
"Peter Koch Larsen" <pklspam@mailme.dk> дÈëÏûÏ¢
news:zRgYd.104094$Vf.3990245@news000.worldonline.dk...
>
> "aka" <akademecia@hotmail.com> skrev i en meddelelse
> news:d0s4l9$kdm$1@news.yaako.com...
> > // classA.cpp : Defines the entry point for the console application.
> > //
> >
> > #include "stdafx.h"
> >
> > #include <iostream>
> >
> > using namespace std;
> >
> > static unsigned int count = 0;
> >
> > class A
> > {
> > public:
> > A() {
> > p = this;
> > }
> >
> > ~A() {
> > if (p) {
> > cout << count++ << endl;
> > delete p;
> > p = 0;
> > }
> > }
> >
> > private:
> > A *p;
> > };
> >
> > int _tmain(int argc, _TCHAR* argv[])
> > {
> > A a;
> >
> > return 0;
> > }
> >
> > /* compiler: MSC++ compiler in visual c++ 2005 express edition beta
> > command: cl /nologo /EHsc classA.cpp
> > */
> >
> > /* result:
> > 0
> > 1
> > 2
> > ...
> > 23485
> > press any key to continue
> > */
> >
> > /*
> > question: Is it an undefined behavior in C++ Standard?
> What is? What you do is calling the destructor of an object more than once
> and that causes undefined behaviour.
> >
> > details: p is a point of class A, when destructor call 'delete p',it
will
> > cause destructor again.
> > Is there any limit calling destructor recursively?
>
> No. You can do as long as you please. Almost! Your program
> Not in your program - it has endless recursion.
>
> Also I fail to sees what youre attempting to do.
>
>
> /Peter
>
> > */ÿÿÿ
> >
> >
>
>
- Previous message: Ioannis Vranos: "Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)"
- In reply to: Peter Koch Larsen: "Re: Is it an undefined behavior in C++ Standard?"
- Next in thread: Victor Bazarov: "Re: Is it an undefined behavior in C++ Standard?"
- Reply: Victor Bazarov: "Re: Is it an undefined behavior in C++ Standard?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|