Hi,
Can anyone explain why the following code works? The static object creation
is via the private ctor. If I try to define a X object in the mainline, of
course I will
get complaint about calling the private ctor.
I ran the code with CW8.3, it works fine. the output is:[color=blue]
>Private ctor
>dtor[/color]
However, if I ran it with VC 6, the output is[color=blue]
>Private ctor.[/color]
Is it compiler problem?
#include <iostream>
class X{
static X sx;
X(){std::cout<< "Private ctor\n";}
public:
~X(){std::cout< <"dtor\n";}
};
X X::sx;
int main(){
return 0;
}
Thanks
Eric
Can anyone explain why the following code works? The static object creation
is via the private ctor. If I try to define a X object in the mainline, of
course I will
get complaint about calling the private ctor.
I ran the code with CW8.3, it works fine. the output is:[color=blue]
>Private ctor
>dtor[/color]
However, if I ran it with VC 6, the output is[color=blue]
>Private ctor.[/color]
Is it compiler problem?
#include <iostream>
class X{
static X sx;
X(){std::cout<< "Private ctor\n";}
public:
~X(){std::cout< <"dtor\n";}
};
X X::sx;
int main(){
return 0;
}
Thanks
Eric
Comment