草庐IT

require_parentheses

全部标签

c++ - 警告: "when type is in parentheses, array cannot have dynamic size"?的原因是什么

我已经发布了一个关于与数组的动态内存分配相关的GCC错误的问题:Anerrorisissuedbygccrelativetoparsingtype-idinanewexpression现在使用ClangHEAD10.0.0我收到以下警告:rog.cc:9:37:warning:whentypeisinparentheses,arraycannothavedynamicsizeint(**a)[N3]=new(int(*[n1])[N3]);~~^~~当我运行这个演示程序时:#includeintmain(){constsize_tN3=4;size_tn1=2;int(**a)[N3]

c++ - 带约束的可变参数模板的 'requires' 表达式的语法是什么?

如果我有一个可变参数模板;templateconceptFooable=requires(Tt){t.bar()->bool;};structFoo{intbig_foo;templateexplicitFoo(T&&i,U&&...f)noexcept:big_foo{std::forward(i)}{Something::something(std::forward(f)...);...}};然后模板的定义及其约束按预期工作。但是如果我“要求”对Foo有更多限制,那么使用“要求”表达式格式,例如;templaterequiresstd::Integral&&Fooable&&Bil

具有预增量 : With or without parentheses is the same? 的 C++ 箭头运算符

类(class)问题:Watchtheparenthesesaroundtheargumentofthe++operator.Aretheyreallyneeded?Whatwillhappenwhenyouremovethem?最初只有一个cout表达式。我添加了另一个以查看差异,如下所示:#includeusingnamespacestd;classClass{public:Class(void){coutvalue=0;coutvalue)value)我的想法是在没有括号的情况下再次测试它,看看有什么不同:...coutvaluevalue两种情况下的结果是一样的。因此我得出结论

c++ - 成员初始化列表符号 : curly braces vs parentheses

考虑pg中的以下代码片段。17的C++之旅:classVector{public:Vector(ints):elem{newdouble[s]},sz{s}{}//constructaVectordouble&operator[](inti){returnelem[i];}//elementaccess:subscriptingintsize(){returnsz;}private:double*elem;//pointertotheelementsintsz;//thenumberofelements};这里我关心的是第三行的成员初始化列表,其中Stroustrup将冒号与两个初始化

C++ 相关名称 : Is this typename required?

在a.hpp中我定义了:#includenamespaceBoard{templatestructGroupNode{usingPointType=std::pair;//...};}然后,在b.cpp中我定义了:#include"a.hpp"namespaceBoard{templatestructNodeList{usingStdList=std::list>;}}//andthenuseNodeListnl;上面的代码可以在没有任何警告的情况下在gcc-6和clang-3.9上编译。但是,Clion2016.3提示cannotresolvevariableGroupNodeinb

c++ - CONCEPT_REQUIRES_ ranges-v3 中的实现

试图学习如何使用EricNiebler的ranges-v3库,并阅读源代码,我看到了宏定义:#defineCONCEPT_PP_CAT_(X,Y)X##Y#defineCONCEPT_PP_CAT(X,Y)CONCEPT_PP_CAT_(X,Y)///\addtogroupgroup-concepts///@{#defineCONCEPT_REQUIRES_(...)\intCONCEPT_PP_CAT(_concept_requires_,__LINE__)=42,\typenamestd::enable_if::type=0\/**/因此,简而言之,模板定义如下:template(

c++ - 在 C++ 中 : Is const reference means "read-only view of" or it requires immutability of object being referenced?

问题可以通过示例表述如下:这段代码有效吗?inta=1;constint&ca=a;++a;//对于MSVC和MinGW,上面的代码片段按预期工作:如果我查询ca后记,它返回2(即它被非常量引用更改)。但问题是:如何从标准的角度考虑这种情况?我们是否可以更改对象,我们有const引用(或者例如,我们必须将ca定义为constvolatile引用以使代码片段正确)?所以,如果上面的片段是正确的,那么这意味着,const引用并不能保证引用的对象是常量。它只是禁止我们通过给定的引用来更改它,即建立引用对象的“只读”View。这是正确的吗?编辑:感谢所有回答我问题的人。答案说明了事情,这对我来

c++ - 错误 C7034 : an array cannot be initialized with a parenthesized initializer

我正在尝试编写一个nativeNode插件,它枚举Windows机器上的所有窗口并将它们的标题数组返回给JSuserland。但是我被这个错误难住了:C:\ProgramFiles(x86)\MicrosoftVisualStudio14.0\VC\include\xmemory0(655):errorC3074:anarraycannotbeinitializedwithaparenthesizedinitializer[C:\xampp\htdocs\enum-windows\build\enumWindows.vcxproj]C:\ProgramFiles(x86)\Micros

c++ - 编译为 C++ 但不是 C(错误 : lvalue required as unary '&' operand)

当我使用C++而不是C时,这一行编译:gmtime(&(*(time_t*)alloca(sizeof(time_t))=time(NULL)));//用alloca创建一个左值我对这种差异感到惊讶。甚至没有针对C++的警告。当我指定gcc-xc时,消息是:playground.cpp:25:8:error:lvaluerequiredasunary'&'operandgmtime(&(*(time_t*)alloca(sizeof(time_t))=time(NULL)));^这里的&不就是一个address-of操作符吗?为什么在C和C++中不同?虽然我可以在C中使用复合字面量,但

c++ - 是否允许在 requires 表达式中为 return-type-requirement 指定类型?

看看这个简单的概念示例:templaterequiresrequires(Tt){{t+t}->bool;}voidfn(){}intmain(){fn();}这里,我使用bool作为return-type-requirement的type-constraint。当前稿says:type-constraint:nested-name-specifieroptconcept-namenested-name-specifieroptconcept-name所以type-constraint必须是一个concept-name。bool(或任何类型)是否允许作为概念名称?如果是,那是什么意思,