草庐IT

If-None-Match

全部标签

c++ - if 语句不起作用并被跳到 else 部分

//thisismysourcefile,.cpp#include#include#include"kingdom.h"namespacewesteros{voiddisplay(KingdompKingdom[],intkingdomElement,stringKingdomName){cout#include"kingdom.h"#includeusingnamespacestd;usingnamespacewesteros;intmain(void){intcount=0;Kingdom*pKingdoms=nullptr;pKingdoms=newKingdom[count];

C++:一种在分隔变量定义和测试的 if 语句中声明一个变量(或多个变量)的方法?

可以这样做:caseWM_COMMAND:if(WORDwNotifyCode=HIWORD(wparam)){...}可以这样做:caseWM_COMMAND:{WORDwNotifyCode=HIWORD(wparam);if(wNotifyCode>1){...}}但是不能这样做:caseWM_COMMAND:if((WORDwNotifyCode=HIWORD(wparam))>1){...}我认为在这里使用for语句是误导性的:caseWM_COMMAND:for(WORDwNotifyCode=HIWORD(wparam);wNotifyCode>1;wNotifyCode

c++ - 为什么这个参数顺序在 regex_match 的原型(prototype)中?

这里是6prototypes的简化版std::tr1::regex_match的regex_match(iterator1,iterator2,match_results&,regex&,flags=some_default);regex_match(iterator1,iterator2,regex&,flags=some_default);regex_match(Elem*,match_results&,regex&,flags=some_default);regex_match(Elem*,regex&,flags=some_default);regex_match(string

c++ - 我们是否需要保护单个赋值或 if 线程安全语句

假设我有:staticintwrite_log=0;void*logger__run(void*arg){//loggerthreadexecution.while(1){//getlogmessagefromsharedqueue.if(write_log){//justcheckingwrite_logvalue.//writelogstillwrite_logistrue.}//destroylogmessage.}}voidlogger__set_logging(intp_write_log){//otherthreadscanstart/stoploggingbylogger

C++11/14 : Wrap a function if it exists

我想编写一个wrapper类(非常像一个代理)来聚合一个对象,并将成员函数调用转发给它。在使用可变参数模板和decltype的C++11/14中,这很简单。我的问题是包装对象可能支持也可能不支持某些成员函数。我想出了一个似乎有效的解决方案,但是,它看起来非常笨拙,我正在寻找简化方法。特别是我担心这在编译时可能会非常昂贵(有许多函数要包装)。这种笨拙是因为需要指定函数的返回类型,而无需decltype某些令人窒息的内容。有人有更好的主意吗?下面这段代码也可用live.#include#include///Computetheresulttypeofamemberfunctioncall,

c++ - 振奋 spirit : how to match any lexer token in qi?

我想将C++函数声明与默认参数值匹配,但忽略这些值。例如:intmyFunction(inta,intb=5+4);这是词法分析器的(一部分):structLexer:boost::spirit::lex::lexer{Lexer(){identifier="[A-Za-z_][A-Za-z0-9_]*";numLiteral="([0-9]+)|(0x[0-9a-fA-F]+)";this->self.add("int")('+')('=')('(')(')')(';')(',')(identifier)(numLiteral);}};我想编写一些解析器规则,例如:function=

c++ - 惰性构造 - 虚拟方法与 if-then stub setter/getter

我的问题的背景是我试图创建一个惰性网格结构,其中网格区域仅在需要时实例化,否则它们在查询时返回默认值。稍微归结一下这个问题,考虑一下我的情况的以下模型:structContainer{std::vectordata;floatget(intindexOuter,intindexInner){returndata[indexOuter].get(indexInner);}}我想stubBase::get在某些情况下函数总是返回相同的值,而在其他情况下我想返回某个数组中的值。我想象两种可能的解决方案。第一个解决方案是在Base上使用标志,即structBase{std::vectordat

c++ - [conv]/6中语句 "The expression e is used as a glvalue if and only if the initialization uses it as a glvalue"的确切含义是什么

[conv]/6(重点是我的):Theeffectofanyimplicitconversionisthesameasperformingthecorrespondingdeclarationandinitializationandthenusingthetemporaryvariableastheresultoftheconversion.TheresultisanlvalueifTisanlvaluereferencetypeoranrvaluereferencetofunctiontype([dcl.ref]),anxvalueifTisanrvaluereferencetoob

带有 std::enable_if 的 C++ 可变参数模板部分模板特化

ITNOA我的问题是如何在可变参数模板部分模板特化场景中使用std::enable_if?例如,我有一个类使用如下所示的可变参数模板部分特化/***Commoncase.*/templatestructfoo;/***Finalsuperclassforfoo.*/templatestructfoo{voidfunc(){}};/***Regularfooclass.*/templatestructfoo:publicfoo{typedefsuperfoo;voidfunc(){coutsuper::templatefunc();}}它工作正常,但如果H是整数类型,我想要特定的部分特化

C++11 std::regex_match 返回额外字符

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Isgcc4.7buggyaboutregularexpressions?我遵循了http://www.cplusplus.com/reference/std/regex/regex_match/上的示例并在Ubuntu12.0464位上使用g++版本4.6.3编译以下是我的输出:stringliteralmatchedstringobjectmatchedrangematchedstringliteralwith3matchesstringobjectwith3matchesrangewith3matche