【发布时间】:2024-04-16 01:25:02
【问题描述】:
在升级 Ubuntu 之前,我一直在使用 gcc 4.8,现在我有了 gcc-4.9.1-16。以前编译时没有警告并且运行良好的代码现在不再编译了。
static const unsigned WIDTH = 16;
static const unsigned VSCALE = 1;
static const unsigned HEIGHT = WIDTH / VSCALE;
static const unsigned FOOTER = 2;
typedef char Row [WIDTH + 1];
typedef Row World [HEIGHT - FOOTER];
std :: vector <World> m_levels;
World levels [] =
{
{
" ",
" ",
" ",
" ",
" ",
" ### ### ",
" ",
"1122112211221122",
" 33003300330033 ",
"1122112211221122",
" 33003300330033 ",
" ",
" ",
" "
},
{
" 44 ",
" 555 55 ",
" 66 66 ",
" 777 777 ",
" 66 66 ",
" 777 777 ",
" 66# #66 ",
" 777 # # 777 ",
" 66 # # 66 ",
" 777 # # 777 ",
" 66# #66 ",
" 555 55 ",
" 44 ",
" "
}
};
// The next line is line 68
m_levels .assign (std :: begin (levels), std :: end (levels));
最后一行错误
.../foo.cpp:68:62: 从这里需要 /usr/include/c++/4.9/bits/stl_algobase.h:373:4:错误:静态断言失败:类型不可分配
.../foo.cpp:68:62: 从这里需要 /usr/include/c++/4.9/bits/stl_construct.h:75:7:错误:数组新 [-fpermissive] 中带括号的初始化程序
编译选项没有改变,据我所知它们是-W -Wall -Wextra -Werror -pedantic --std=c++0x,只有 gcc 发生了变化。
为什么这段代码不再编译?
【问题讨论】: