查看: 1499|回复: 2
|
为何不能在C++里设定初值?
[复制链接]
|
|
小弟有一支program经简化之後,如下:
class aaa {
public :
aaa() { };
private :
static int abc[] = {0, 7, 3, 5, 1, 6, 2, 4};
}
int main(int argc, char **argv)
{
aaa a;
}
设定初值总是会有下面两行错误
show.cpp:5: error: a brace-enclosed initializer is not allowed here before '{' token
show.cpp:5: error: invalid in-class initialization of static data member of non-integral type `int[]'
compiler 是gcc 3.4.3, os 是rhel AS 4.0
请各位大大指教. |
|
|
|
|
|
|
|
发表于 8-5-2007 08:46 AM
|
显示全部楼层
经过更改的code:
class aaa {
public :
aaa() { };
private :
static int abc[] ;
}; //记得要在 class 的 } 之后加上一个 ; 要不然就会有问题。
int aaa::abc[] = {0, 7, 3, 5, 1, 6, 2, 4}; //static data member has to be initialized this way
int main(int argc, char **argv)
{
aaa a;
} |
|
|
|
|
|
|
|

楼主 |
发表于 8-5-2007 11:29 AM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|