草庐IT

is_const_method

全部标签

java - Switch 语句 : Is the logic different in C v/s. Java 等其他语言?

我正在浏览thisC编程教程。它说:Theswitch-statementisactuallyentirelydifferent(fromotherlanguages)andisreallya"jumptable".Insteadofrandombooleanexpressions,youcanonlyputexpressionsthatresultinintegers,andtheseintegersareusedtocalculatejumpsfromthetopoftheswitchtothepartthatmatchesthatvalue.Here'ssomecodethatw

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++ - 错误 : argument of type char* is incompatible with parameter of type LPCWSTR

#include#includeusingnamespacestd;intmain(){char*file="d:/tester";WIN32_FIND_DATAFindFileData;HANDLEhFind;hFind=FindFirstFile(file,&FindFileData);//lineoferrorsaysargumentoftypechar*isincompatiblewithparameteroftypeLPCWSTR}我无法理解错误。错误是什么以及如何解决错误?我正在制作一个控制台应用程序,需要检查目录中是否有文件。 最佳答案

c++ - 获取 std::set 元素地址时从 ‘const int*’ 到 ‘int*’ 的无效转换

我收到以下错误error:invalidconversionfrom‘constint*’to‘int*’以下是我的程序#includeintmain(intargc,char**argv){std::setintSet;intSet.insert(1);intSet.insert(2);intSet.insert(3);intSet.insert(4);intSet.insert(5);int*pAddress=&(*(intSet.find(4)));}我想要std::set中元素的地址,此代码不会给Microsoft编译器带来任何编译错误,但g++会给出此编译错误。

c++ - 资格调整(const/volatile)可能导致歧义

谁能帮我理解为什么当getter是const时下面的代码无法编译(VS2010)?测试代码如下:#includeclasssocket{public://setter-throwexceptionversionvoidnon_blocking(boolmode){//...}//getter-errorcodeversionboolnon_blocking(boost::system::error_code&ec)const{//...}//setter-errorcodeversionvoidnon_blocking(boolmode,boost::system::error_cod

c++ - 如何识别代码中const char*和const char[]的类型?

constchar*s1="teststirg";constchars2[]="teststirg";我想要一个方法告诉我s1是“char*”而s2是“char[]”,怎么写这个方法? 最佳答案 使用模板:templateboolIsArray(T(&a)[SIZE]){returntrue;}templateboolIsArray(T*p){returnfalse;}这将在运行时进行评估。用法:if(IsArray(s1))...if(IsArray(s2))...如果有兴趣,您可以使用一些高级技术,它会告诉您这是编译时间。编辑:

c++ - static const string 成员变量是否总是在使用前初始化?

在C++中,如果我想定义一些non-localconststring,可以在不同的类、函数、文件中使用,我知道的方法是:使用定义指令,例如#defineSTR_VALUE"some_string_value"const类成员变量,例如classDemo{public:staticconststd::stringConstStrVal;};//thenincppstd::stringDemo::ConstStrVal="some_string_value";const类成员函数,例如classDemo{public:staticconststd::stringGetValue(){ret

c++ - 右值或左值 (const) 引用参数

我想通过r-或l-值(const)引用将参数(某种具体类型,比如int)传递给成员函数。我的解决方案是:#include#includestructF{usingdesired_parameter_type=int;template::type,desired_parameter_type>::value>::type>voidoperator()(X&&x)const{//orevenstatic_assert(std::is_same::type,desired_parameter_type>::value,"");std::forward(x);//somethinguseful

c++ - 使 C++ 变量成为 const

我喜欢“const”。我希望每个“应该是常量”的变量和方法都是“常量”。问题是变量或方法是否“应该是常量”取决于调用树中更下方的方法/变量。是否有某种工具或某种过程可用于静态检查代码体并执行“自下而上的常量化”? 最佳答案 我不知道你问题的答案,但我想反驳这种说法whetheravariableormethod"oughttobeconst"dependsonmethods/variablesfurtherdowninthecalltree其实const应该是逻辑层面的。IE。如果逻辑上不应更改,则应将其标记为const。如果稍后是

c++ - 如果右值没有绑定(bind)到 const 引用,这将如何影响移动语义和完美转发?

在http://www.reddit.com/r/IAmA/comments/1nl9at/i_am_a_member_of_facebooks_hhvm_team_a_c_and_d/ccjm2qs,AndreiAlexandrescu写道:IthinkbindingrvaluestoconstreferenceshasbeenthesmallmistakethatcausedthervaluereferencesHindenburg...Itwouldbealongdiscussion.Bindingrvaluestoconst&madesensewhenfirstintroduc