T
thomas
hi guys,
-----code-----
class A{
private:
A(){}
public:
static A *getInstance(){
static A *a = new A(); //-------L1----
return a;
}
};
-----code-----
I use the static keyword to declare a static instance A,
I wonder if getInstance() is called multiple times, will L1 be
executed multiple times?
generally a initialization sentence of static variable will be
executed only once, but I'm not sure what will the c++ compiler expand
for L1.
-----code-----
class A{
private:
A(){}
public:
static A *getInstance(){
static A *a = new A(); //-------L1----
return a;
}
};
-----code-----
I use the static keyword to declare a static instance A,
I wonder if getInstance() is called multiple times, will L1 be
executed multiple times?
generally a initialization sentence of static variable will be
executed only once, but I'm not sure what will the c++ compiler expand
for L1.