[英]C++ static class variable initialization
#include<string>
class abc
{
public:
static const abc PENDING;
private:
static const string PENDING_STATUS_CD;
abc ( const string& iStatus )
{
//...........
Logintodatabase();
//.............
logoutfromdatabase();
}
};
const string abc::PENDING_STATUS_CD = "P";
const abc abc::PENDING ( abc::PENDING_STATUS_CD );
at calling of line const abc abc::PENDING ( abc::PENDING_STATUS_CD );在调用行 const abc abc::PENDING ( abc::PENDING_STATUS_CD ); will call constructor?会调用构造函数吗?
Define your PENDING_STATUS_CD
outside of the class definition.在类定义之外定义PENDING_STATUS_CD
。 Your current implementation creates a static instance variable witch doesn't make sense.. Statics are by definition not instance variables..Anyway, try that and see what happens.您当前的实现创建了一个没有意义的静态实例变量.. 静态是根据定义而不是实例变量..无论如何,试试看会发生什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.