草庐IT

ANOTHER_CONSTANT

全部标签

C++1y/C++14 : Assignment to object outside its lifetime is not allowed in a constant expression?

根据当前草案,以下C++14/C++1y程序是否格式错误?#includetemplatestructliteral_array{Tdata[n];};templateconstexprliteral_arrayoperator+(literal_arraya,literal_arrayb){literal_arrayx;for(size_ti=0;ia={1,2,3};constexprliteral_arrayb={4,5};constexprautoc=a+b;}Clangtrunk(在撰写本文时)给出:error:constexprvariable'c'mustbeinitia

c++ - 有没有一种正统的方法来避免编译器警告 C4309 - "truncation of constant value"与二进制文件输出?

我的程序执行将二进制数据写入文件的常见任务,符合某种非文本文件格式。由于我正在写入的数据尚未存在于现有block中,而是在运行时逐字节放在一起,因此我使用std::ostream::put()而不是write().我认为这是正常程序。该程序运行良好。它同时使用std::stringstream::put()和std::ofstream::put()以两位十六进制整数作为参数。但是我得到编译器警告C4309:"truncationofconstantvalue"(inVC++2010)每当参数到put()大于0x7f。显然编译器期待signedchar,常数超出范围。但我认为实际上并没有

c++ - 有没有一种正统的方法来避免编译器警告 C4309 - "truncation of constant value"与二进制文件输出?

我的程序执行将二进制数据写入文件的常见任务,符合某种非文本文件格式。由于我正在写入的数据尚未存在于现有block中,而是在运行时逐字节放在一起,因此我使用std::ostream::put()而不是write().我认为这是正常程序。该程序运行良好。它同时使用std::stringstream::put()和std::ofstream::put()以两位十六进制整数作为参数。但是我得到编译器警告C4309:"truncationofconstantvalue"(inVC++2010)每当参数到put()大于0x7f。显然编译器期待signedchar,常数超出范围。但我认为实际上并没有

c++ - Eclipse CDT C/C++ : Include a header file from another project

我在EclipseCDTma​​in和shared中有两个c++项目。在shared中,我有一个名为calc.h的header。我想在ma​​in中使用这个header,所以我做了以下操作:在ma​​in的相关文件中添加了#include"calc.h在ma​​in的properties->Projectreferences中,我检查了shared我希望这会起作用,但我在编译时收到fatalerror:calc.h:Nosuchfileordirectory,所以项目引用不知何故不起作用。我可以通过在ma​​in的properties->C/C++Build->Setting->中手动

c++ - Eclipse CDT C/C++ : Include a header file from another project

我在EclipseCDTma​​in和shared中有两个c++项目。在shared中,我有一个名为calc.h的header。我想在ma​​in中使用这个header,所以我做了以下操作:在ma​​in的相关文件中添加了#include"calc.h在ma​​in的properties->Projectreferences中,我检查了shared我希望这会起作用,但我在编译时收到fatalerror:calc.h:Nosuchfileordirectory,所以项目引用不知何故不起作用。我可以通过在ma​​in的properties->C/C++Build->Setting->中手动

c++ - 为什么我们需要两个定义: integral constant expression and converted constant expression?

C++14中的§5.19/3定义了一个整型常量表达式和一个转换后的常量表达式:Anintegralconstantexpressionisanexpressionofintegralorunscopedenumerationtype,implicitlyconvertedtoaprvalue,wheretheconvertedexpressionisacoreconstantexpression.[Note:Suchexpressionsmaybeusedasarraybounds(8.3.4,5.3.4),asbit-fieldlengths(9.6),asenumeratorini

c++ - 为什么我们需要两个定义: integral constant expression and converted constant expression?

C++14中的§5.19/3定义了一个整型常量表达式和一个转换后的常量表达式:Anintegralconstantexpressionisanexpressionofintegralorunscopedenumerationtype,implicitlyconvertedtoaprvalue,wheretheconvertedexpressionisacoreconstantexpression.[Note:Suchexpressionsmaybeusedasarraybounds(8.3.4,5.3.4),asbit-fieldlengths(9.6),asenumeratorini

C++ STL : Custom sorting one vector based on contents of another

这个问题在这里已经有了答案:HowdoIsortastd::vectorbythevaluesofadifferentstd::vector?[duplicate](13个回答)关闭8年前。这可能是最好的例子。我有两个vector/列表:People={Anne,Bob,Charlie,Douglas}Ages={23,28,25,21}我想使用sort(People.begin(),People.end(),CustomComparator)之类的方法根据年龄对People进行排序,但我不知道如何编写CustomComparator查看年龄而不是人物。 最

C++ STL : Custom sorting one vector based on contents of another

这个问题在这里已经有了答案:HowdoIsortastd::vectorbythevaluesofadifferentstd::vector?[duplicate](13个回答)关闭8年前。这可能是最好的例子。我有两个vector/列表:People={Anne,Bob,Charlie,Douglas}Ages={23,28,25,21}我想使用sort(People.begin(),People.end(),CustomComparator)之类的方法根据年龄对People进行排序,但我不知道如何编写CustomComparator查看年龄而不是人物。 最

C++ 警告 : deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

我正在使用gnuplot在C++中绘制图形。该图正在按预期绘制,但在编译期间出现警告。警告是什么意思?warning:deprecatedconversionfromstringconstantto‘char*’[-Wwrite-strings]这是我正在使用的功能:voidplotgraph(doublexvals[],doubleyvals[],intNUM_POINTS){char*commandsForGnuplot[]={"settitle\"ProbabilityGraph\"","plot'data.temp'withlines"};FILE*temp=fopen("da