473,322 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

destructor and namespace with vs6 sp0/5 and !g++

using visual studio 6 with service pack 0 and 5, why does the distructor of
a class contained inside a namespace isn't called and instead it's called
when:
- iostream.h is included instead of iostream
- "using namespace std;" is commented
?

the destructor of a2 (not contained inside the namespace) is always called.

this problem seems to afflict only visual studio 6 service pack 0 and 5 and
under linux g++ it works fine.

note that the constructor of both a1 and a2 are called and the problem
persist even making a1 a global variable (removing it from the namespace c).

//----------
#include <iostream>
using namespace std;

class a{
public:
a(){cout << "a()" << endl;}
~a(){cout << "a~()" << endl;}
};

namespace c{
a a1;
}

int main(){
a a2;
return 0;
}
//EOF

output:
a()
a()
a~()

bye, demo
Jul 22 '05 #1
6 1671

"demo" <je******@libero.it> wrote in message
using visual studio 6 with service pack 0 and 5, why does the distructor of a class contained inside a namespace isn't called and instead it's called
when:
- iostream.h is included instead of iostream
- "using namespace std;" is commented
?


Problem with VC 6, but then you are using a compiler that is about 8 years
old. If possible get VC 7.x which get this example right.

Sharad
Jul 22 '05 #2

demo wrote:
using visual studio 6 with service pack 0 and 5, why does the distructor of a class contained inside a namespace isn't called and instead it's called when:
- iostream.h is included instead of iostream
- "using namespace std;" is commented
?


[ snip example trying to see if a dtor is called by inserting a cout ]

You're using the std::cout object. This should be destroyed fairly
late in the shutdown process, but VC6 destroys it early. That doesn't
mean your dtor isn't called. It is called, it can't produce output.

iostream.h is an older microsoft header, not on-topic here, and I've
got no idea when or how it's ::cout object is destroyed.
Regards,
Michiel Salters

Jul 22 '05 #3
msalters wrote:

iostream.h is an older microsoft header, not on-topic here,


you can use .h headers if you want to, they're just deprecated. :-)

[OT] Anyway VC++ has a whiz bang interface but the compiler sucks.

--

Cheers
--
Hewson::Mike
"This letter is longer than usual because I lack the time to make it
shorter" - Blaise Pascal
Jul 22 '05 #4

"Mike Hewson" <he******@optusnet.com.au> wrote in message
msalters wrote: [OT] Anyway VC++ has a whiz bang interface but the compiler sucks.


It's quite good after after v7.1.
Jul 22 '05 #5
Sharad Kala wrote:
"Mike Hewson" <he******@optusnet.com.au> wrote in message
[OT] Anyway VC++ has a whiz bang interface but the compiler sucks.

It's quite good after after v7.1.


Oooo...

I've got VC++ 6 sp5, BUT I've slid in Comeau's compiler 4.3.3 as a
'tool' - so it compiles with Comeau ( compliance!! ) then hands over C
code to the native MS compiler ( linking etc from there on ). Some name
mangling issues for debugging, though not terrible. I'm aiming for a
spread of compilers in similiar vein - Digital Mars, Bloodshed, Mingw
etc. If any one wants to know the skinny on how to do that email me.

Oh... and ... ( I write this attempting to cheekily avoid OT snipes :-) )

*COMPLIANCE IS IMPORTANT*

--

Cheers
--
Hewson::Mike
"This letter is longer than usual because I lack the time to make it
shorter" - Blaise Pascal
Jul 22 '05 #6
> msalters wrote:

iostream.h is an older microsoft header, not on-topic here,
you can use .h headers if you want to, they're just deprecated. :-)


Only the C headers have .h forms. There never is and never was
an iostream.h, fstream.h, etc.
[OT] Anyway VC++ has a whiz bang interface but the compiler sucks.

This has been addressed in later versions, from what I've heard

Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Stub | last post by:
Please answer my questions below - thanks! 1. Why "Derived constructor" is called but "Derived destructor" not in Case 1 since object B is new'ed from Derived class? 2. Why "Derived destructor"...
20
by: frs | last post by:
For memory economization, I need to get rid if the virtual destructor. Under this constraint I get caught up in a design, where I need to call a destructor of a derived class from a base class....
6
by: MirzaD | last post by:
Hello Below you will find the problematic program. It is a string wrapper class with a bare minimum of functionality to keep things simple. **Code** //StringClass.h #include <iostream>...
5
by: junw2000 | last post by:
I use the code below to study delete and destructor. #include <iostream> using namespace std; struct A { virtual ~A() { cout << "~A()" << endl; }; //LINE1 void operator delete(void* p) {...
3
by: yancheng.cheok | last post by:
Hello all, I try to figure out what is the sequence when we create and delete an object. After experiment on my VC++ 2003, I found that here is the sequence new-constructor-destructor-delete ...
4
by: David | last post by:
Hi all, something wrong with my code, it seems that the destructor function has been called twice. I don't know why.here is my codes Fixture.h #ifndef _FIXTURE_H #define _FIXTURE_H #include...
4
by: Subra | last post by:
Hi, I am learning C++ and need export advice on the below program. I have read it that whenever a exception is genrated and control enteres the catch block it will call destructors for all the...
3
by: Rudi | last post by:
Hello, following problem: At program end or release an assembly a serial device should get a final exit sequence. How can I do this? With Dispose() it's no problem, but this assembly is used...
3
by: GAURAV AGRAWAL | last post by:
Hi Guys, Can someone please explain me why this is happening #include<iostream> using namespace std; class a { public: int a1; // If I remove this it'll work fine
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.