#include <stdio.h>
struct modelCatalog {
int m_a;
modelCatalog(): m_a(777) {}
};
class G4PhysicsModelCatalog
{
public:
G4PhysicsModelCatalog();
static modelCatalog* catalog;
};
G4PhysicsModelCatalog::G4PhysicsModelCatalog()
{ if(!catalog) {
static modelCatalog catal;
catalog = &catal;
}
}
modelCatalog* G4PhysicsModelCatalog::catalog;
/*
G4int G4PhysicsModelCatalog::Register(const G4String& name)
{
G4PhysicsModelCatalog();
....
}
*/
int main()
{
printf("catalog before = %p\n", G4PhysicsModelCatalog::catalog);
G4PhysicsModelCatalog();
printf("catalog after= %p m_a = %d\n", G4PhysicsModelCatalog::catalog, G4PhysicsModelCatalog::catalog->m_a);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgpzdHJ1Y3QgbW9kZWxDYXRhbG9nIHsKICAgIGludCBtX2E7CiAgICBtb2RlbENhdGFsb2coKTogbV9hKDc3Nykge30KfTsKCmNsYXNzIEc0UGh5c2ljc01vZGVsQ2F0YWxvZwp7CiAgcHVibGljOgogIEc0UGh5c2ljc01vZGVsQ2F0YWxvZygpOwogIHN0YXRpYyBtb2RlbENhdGFsb2cqIGNhdGFsb2c7Cn07CgpHNFBoeXNpY3NNb2RlbENhdGFsb2c6Okc0UGh5c2ljc01vZGVsQ2F0YWxvZygpCnsgaWYoIWNhdGFsb2cpIHsgCiAgICBzdGF0aWMgbW9kZWxDYXRhbG9nIGNhdGFsOwogICAgY2F0YWxvZyA9ICZjYXRhbDsgCiAgfSAKfQoKbW9kZWxDYXRhbG9nKiBHNFBoeXNpY3NNb2RlbENhdGFsb2c6OmNhdGFsb2c7Ci8qCkc0aW50IEc0UGh5c2ljc01vZGVsQ2F0YWxvZzo6UmVnaXN0ZXIoY29uc3QgRzRTdHJpbmcmIG5hbWUpCnsKICBHNFBoeXNpY3NNb2RlbENhdGFsb2coKTsKICAuLi4uIAp9CiovCmludCBtYWluKCkKewogICAgcHJpbnRmKCJjYXRhbG9nIGJlZm9yZSA9ICVwXG4iLCBHNFBoeXNpY3NNb2RlbENhdGFsb2c6OmNhdGFsb2cpOwogICAgRzRQaHlzaWNzTW9kZWxDYXRhbG9nKCk7CiAgICBwcmludGYoImNhdGFsb2cgYWZ0ZXI9ICVwIG1fYSA9ICVkXG4iLCBHNFBoeXNpY3NNb2RlbENhdGFsb2c6OmNhdGFsb2csICBHNFBoeXNpY3NNb2RlbENhdGFsb2c6OmNhdGFsb2ctPm1fYSk7CiAgICByZXR1cm4gMDsgCn0=