T
thomas
URL: http://www.parashift.com/c++-faq-lite/ctors.html
The FAQ 10.14 says that "pointer to static object" is preferrable to
"static object" because of problems when deinitialization.
I don't quite get it.
I think static object will exist with the existance of a class. Where
comes the deinitialization?
example: --------code-------------
#include<iostream>
using namespace std;
class Fred{
public:
Fred(){};
void gobowling(){}
};
Fred& x(){
static Fred ans;
return ans;
}
int main(){
x().gobowling();
}
--------------
The static object created with x() will never be destructed until
program exits.
Another example: -----------code----------
#include<iostream>
using namespace std;
class Fred{
public:
Fred(){};
void gobowling(){}
Fred& x(){
static Fred ans;
return ans;
}
};
int main(){
Fred p;
p.x().gobowling();
}
The FAQ 10.14 says that "pointer to static object" is preferrable to
"static object" because of problems when deinitialization.
I don't quite get it.
I think static object will exist with the existance of a class. Where
comes the deinitialization?
example: --------code-------------
#include<iostream>
using namespace std;
class Fred{
public:
Fred(){};
void gobowling(){}
};
Fred& x(){
static Fred ans;
return ans;
}
int main(){
x().gobowling();
}
--------------
The static object created with x() will never be destructed until
program exits.
Another example: -----------code----------
#include<iostream>
using namespace std;
class Fred{
public:
Fred(){};
void gobowling(){}
Fred& x(){
static Fred ans;
return ans;
}
};
int main(){
Fred p;
p.x().gobowling();
}