D
demo
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
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