首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于类的静态常量引用的有关问题

2012-03-07 
关于类的静态常量引用的问题?定义的类string{private:staticconstintCINLIM80....public:friendistream&

关于类的静态常量引用的问题?
定义的类
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},即可使用

热点排行