草庐IT

declarative-programming

全部标签

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++ - SDL2 & GDB : program received signal ?,未知信号

让我们从描述发生的事情开始:我正在Windows上使用SDL2库。我可以使用它编译程序,当我运行.exe时,它​​工作得很好。当我尝试使用GDB调试它时出现问题-当代码进入SDL_Init或SDL_OpenAudio函数(可能创建新线程)时,GDB停止,显示“程序收到信号?,未知信号”消息,当我恢复执行时程序崩溃。显然GDB(https://www.mail-archive.com/cygwin@cygwin.com/msg149735.html)中存在与线程命名相关的错误,应该在GDB版本7.11.1-1中修复。起初我使用GCC5.1.0(TDM)和GDB7.6.1,所以我决定更新到

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

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

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++ - Boost Program_options 配置文件注释

我有一个程序使用boost::program_options从配置文件中读取大量变量。配置文件正在运行并读取值,但是由于文件中有很多选项,我想将它们记录在案。例如我希望配置文件看起来像:#Hereisadescriptionofflag1#flag1=truemeansblahblahblah#flag1=falsemeans...flag1=true#Hereisadescriptionofflag2...问题是我在任何地方都找不到描述执行此操作的方法的文档。我相当确定我可以使用诸如a=之类的东西对于我的评论分隔符,只需将所有评论分配给std::vector解析后被丢弃,但是我想知道

c++ - 通过 using-directive 在 using-declaration 中查找名称

根据c++标准,下面的程序是良构还是病构的?namespaceN{inti;}usingnamespaceN;using::i;intmain(){}我用不同的编译器得到不同的结果:Clang(http://melpon.org/wandbox/permlink/c8vl7XbumyyS6vsw):没有错误。GCC(http://melpon.org/wandbox/permlink/immhNeWFCMcCA800):错误:'i'未声明。根据c++标准,这个程序是良构还是病构的?需要对c++标准的引用。我想弄清楚我应该为哪个编译器提交错误。 最佳答案

c++ - 模板 friend 类 : Forward Declaration or. ..?

假设我有一个模板类,我试图将其声明为友元类。我应该转发声明类还是给它自己的模板?例子:templateclassSLinkedList;templateclassSNode{private:Eelem;SNode*next;friendclassSLinkedList;};或者templateclassSNode{private:Eelem;SNode*next;templatefriendclassSLinkedList;}; 最佳答案 您的第一种方法可能就是您想要的。它将使SLinkedListSNode的friend,并且所有

c++ - 在 Boost::Program_Options 中,如何设置 wstring 的默认值?

我的下面的代码没有工作:wstringconfig_file;//Declareagroupofoptionsthatwillbe//allowedonlyoncommandlinepo::options_descriptiongeneric("Genericoptions");generic.add_options()("help,h","producehelpmessage")("config,c",po::wvalue(&config_file)->default_value(L"DXDrv.cfg"),"nameofafileofaconfiguration.");编译失败,错