2011年3月30日 星期三

const string in class

 常數字串須在類別外初始化

http://bbs.chinaunix.net/archiver/?tid-953427.html

fiowrf 发表于 2007-06-25 11:38
class Operator:public BaseStructure{
private:
        OperatorType mType;
        static int ar[6];
        static const string OperatorSymbol[7]={"+","-","*","/","^","??"};
public:
}
结果提示错误:
Operator.hxx:13: error: invalid in-class initialization of static data member
of non-integral type `const std::string[7]'

_Erics 发表于 2007-06-25 12:53
在类外初始化
class Operator:public BaseStructure{
private:
        OperatorType mType;
        static int ar[6];
        static const string OperatorSymbol[7];
public:
}
const string Operator:OperatorSymbol[]={"+","-","*","/","^","??"};

gooderfeng 发表于 2007-06-25 13:00
静态数据在c++中只有 static const int t = 0;
可以初始化。
其他都要在类的外面。

沒有留言:

張貼留言