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 6 1698
"demo" <je******@liber o.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
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
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
"Mike Hewson" <he******@optus net.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.
Sharad Kala wrote: "Mike Hewson" <he******@optus net.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
> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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" is called in Case 2 since only ~base() becomes
"virtual" and ~Derived() is still non-virtual?
3. Does Case 3 show that we don't need any virtual destructor to make
~Derived() called?
4. Is "virtual destructor" needed only for Case 2?
|
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. Briefly it could be displayed like the code below.
It ends up deleting the member 'x' of 'B' twice. Why? Is there
a way around?
Thanks
Frank
|
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>
#include <cstring>
|
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) {
cout << "A::operator delete" << endl;
|
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
What I am concern is, is this sequence a C++ standard specification? Or
it is compiler dependent?
Thank you. Here is the code I use to perform experiment:
| |
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 <string>
#include <map>
#include <list>
|
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
successfuly completed constructors. But in the below case
i am doing :-
base *ptr=new base;
throw 44;
But the destructor for base is not called once it enters the catch
|
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 in a com
interop dll and it must be guaranteed, that the final sequence is send
to the serial device, when the calling application dont send Close() or
Dispose().
|
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
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |