草庐IT

variable-declaration

全部标签

c++ - 为什么C++标准中的declaration-seq是这样写的?

declaration-seq:declarationdeclaration-seqdeclaration不是这样的:declaration-seq:declarationdeclarationdeclaration-seq这两个定义可以互换吗?它们有什么区别? 最佳答案 这是C++的C遗产的遗迹。C语法(几乎)是LALR(1),因此使用leftrecursion越多越好。C++语法甚至不再是模糊的LALR,但许多规则仍然以LALR解析器更喜欢的形式编写,因为没有理由改变它们——任何强大到足以处理C++的解析器算法都不关心哪种类型的

c++ - 不合格的名称查找 : Why local declaration hides declaration from using directive

考虑这段代码:namespaceA{inti=24;}namespaceB{usingnamespaceA;inti=11;intk=i;//findsB::i,noambiguity}和basic.lookup.unqual.2:§6.4.1Unqualifiednamelookup[basic.lookup.unqual]Thedeclarationsfromthenamespacenominatedbyausing-directivebecomevisibleinanamespaceenclosingtheusing-directive;see[namespace.udir].F

c++ - 前向声明的类型和 "non-class type as already been declared as a class type"

我对以下代码有疑问:templatevoidfoo(structbar&b);structbar{};intmain(){}它在GCC上编译成功,但在MSVC(2008)上编译失败并出现以下错误:C2990:“bar”:已声明为类类型的非类类型是代码错误还是MSVC中的错误?如果我在模板定义之前添加structbar;就可以了。 最佳答案 我们有我们的赢家:https://connect.microsoft.com/VisualStudio/feedback/details/668430/forward-declared-type-

c++ - Clang VS VC++ :"error: declaration of ' T'阴影模板参数”

我正在尝试为theclassiccopy&swapidiom编译以下代码在我的Mac上使用clang3.3templateclassnode{private:node*left;node*right;Tvalue;public:friendvoidswap(node&,node&);//otherstuff}然而链接器却报错了。我现在明白我应该将函数声明为模板。但是,如果我按照建议的样式进行操作,则会发生错误here来自MSDN:templateclassArray{T*array;intsize;public:template//...templatefriendArray*comb

C++11 我可以确保 condition_variable.wait() 不会错过通知吗?

我让线程1执行以下代码:unique_lockul(m);while(condition==true)cv.wait(ul);线程2执行这段代码:condition=false;cv.notify_one();不幸的是,我遇到了时间问题:T1:conditioncheckstrueT2:conditionsettofalseT2:cv.notify_one()T1:cv.wait()线程1完全错过了通知并在wait()上保持阻塞状态。我尝试使用带有谓词但结果基本相同的wait()版本。也就是说,谓词的主体执行检查,但在它返回之前,条件的值被更改并发送通知。然后谓词返回。我该如何解决这个

c++ - 错误 : variable or field ‘myfunction’ declared void

这个问题在这里已经有了答案:variableorfielddeclaredvoid(6个答案)关闭7年前。在下文中,我没有定义类型doesntexist。voidmyfunction(doesntexistargument){}GCC4.7.2说“error:variableorfield‘myfunction’declaredvoid”我的问题是:编译器在这里指代函数名称为void而不是参数类型是怎么想的?[编辑]在投票之前,请注意这个问题的答案与错误的顺序和-Wfatal-errors停止打印更直接相关的消息有关。这不仅仅是我在尝试一个稍微模糊的编译器消息。

c++ - 错误 C4703 : potentially uninitialized local pointer variable 'pNamesPtr' used

我正在做一个加密项目,在尝试编译程序时遇到了以下错误。main.cpp(520):errorC4703:potentiallyuninitializedlocalpointervariable'pNamesPtr'used==========Build:0succeeded,1failed,0up-to-date,0skipped==========DLLNAMES[i].UsedAlready=0;}*dwOutSize=(DWORD)pNamesPtr-(DWORD)pBuffer;//*有人可以帮我解决这个错误吗?您是否需要更多代码才能得到好的答案?

c++ - 为什么编译器说 : 'enable_if' cannot be used to disable this declaration

templateusingEnable_if=typenamestd::enable_if::type;classDegree;templateconstexprinlineboolIs_Degree(){returnstd::is_base_of::value;}classDegree{public:std::size_tinDeg=0;};templateclassVertex:publicSatellite{public:explicitVertex(intnum):n(num){}private:std::size_tn;};templateclassEdge{public:/

C++ 调试窗口显示“<incomplete type> for string variable

据我所知,我正在以一种相当正常的方式初始化一个字符串,当我调试时,我的IDE(CLion)中的变量窗口将其值显示为.我有一些简单的代码导致字符串变量Bob出现问题.#includeintmain(){std::stringBob="thisdoesn'tshowupinthevariableswindow";std::cout我不知道它有什么影响,但我会包含CMakeLists文件,它似乎是我可以使用的最简单的文件。cmake_minimum_required(VERSION3.8)project(testing123)set(CMAKE_CXX_FLAGS"${CMAKE_CXX_F

c++ - `std::condition_variable::wait_for` 经常调用谓词

考虑以下代码片段:#include#include#include#includeintmain(){std::mutexy;std::condition_variablex;std::unique_locklock{y};inti=0;autoincrement=[&]{++i;returnfalse;};usingnamespacestd::chrono_literals;//lock5sifincrementreturnsfalse//let'sseehowoftenwasincrementcalled?x.wait_for(lock,5s,increment);std::cou