在升级 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: required from here /usr/include/c++/4.9/bits/stl_algobase.h:373:4: error: static assertion failed: type is not assignable
.../foo.cpp:68:62: required from here /usr/include/c++/4.9/bits/stl_construct.h:75:7: error: parenthesized initializer in array new [-fpermissive]
编译选项没变,都是-W -Wall -Wextra -Werror -pedantic --std=c++0x据我所知,只有 gcc 发生了变化。
为什么这段代码不再编译?
最佳答案
标准容器对值类型的最低要求是它们必须是Erasable。对于默认分配器,这转化为给定 value_type *p; 的要求,p->~value_type(); 必须格式正确。
如果 value_type 是一个类类型,它只是调用析构函数,并且如果析构函数没有被删除并且是可访问的,那么它就是良构的。如果 value_type 表示标量类型,p->~value_type(); 也是有效的并且是空操作(这称为 伪析构函数调用).但是,如果 value_type 是数组类型,则 p->~value_type(); 无效。
因此,内置数组永远不是标准容器的有效值类型,至少在使用默认分配器时是这样。 (各种其他容器操作对值类型提出了更多要求;内置数组至少会与其中一些操作冲突,因为它们不可分配。)
使用不满足模板要求的类型实例化标准库模板会导致未定义的行为。似乎 libstdc++ 偶然没有诊断出您的错误,直到 GCC 4.9 附带的版本。
顺便说一句,修复很简单。只需使用 std::array。
关于c++ - 我不能再将 char[M][N] 类型分配给 gcc 4.9 上的 std::vector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27695600/
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我
我有一个.pfx格式的证书,我需要使用ruby提取公共(public)、私有(private)和CA证书。使用shell我可以这样做:#ExtractPublicKey(askforpassword)opensslpkcs12-infile.pfx-outfile_public.pem-clcerts-nokeys#ExtractCertificateAuthorityKey(askforpassword)opensslpkcs12-infile.pfx-outfile_ca.pem-cacerts-nokeys#ExtractPrivateKey(askforpassword)o
我正在尝试将$stdout设置为临时写入一个文件,然后返回到一个文件。test.rb:old_stdout=$stdout$stdout.reopen("mytestfile.out",'w+')puts"thisgoesinmytestfile"$stdout=old_stdoutputs"thisshouldbeontheconsole"$stdout.reopen("mytestfile1.out",'w+')puts"thisgoesinmytestfile1:"$stdout=old_stdoutputs"thisshouldbebackontheconsole"这是输出。r
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上