关于类的静态常量引用的问题?
定义的类
string
{
private:
static const int CINLIM = 80;
....
public:
friend istream & operator> > (istream & is, String & st); //友元
}
istream & operator> > (istream & is, String & st)
{
char temp[String::CINLIM];
is.get(temp, String::CINLIM);
if (is)
st = temp;
while (is && is.get() != '\n ')
continue;
return is;
}
运行在VC6下,编译时出现:
illegal pure syntax,must be '=0 '
pure specifier can only be specified for functions
[解决办法]
string
{
private:
static const int CINLIM = 80;
....
public:
friend istream & operator> > (istream & is, String & st); //友元
}
改为
string
{
private:
static const int CINLIM;
....
public:
friend istream & operator> > (istream & is, String & st); //友元
}
const int string::CINLIM = 80;
[解决办法]
static const int string::CINLIM = 80;
这种表达方法VC6并不支持,你可以像楼上说的那样分开写,在类内写
static const int CINLIM
在类外写
const int string::CINLIM = 80;
用enum的话就在类内写:eunm{CINLIM=80},即可使用