草庐IT

is_const_method

全部标签

c++ - 为什么 operator char*() 在 bool 上下文中覆盖 operator bool() const?

似乎在c++中,在纯bool上下文中,operatorchar*()的优先级高于operatorbool()const;并启用c++11模式和使用explicitoperatorbool()const没有帮助。这是g++中的错误还是语言标准中的错误?或者我没有看到这种疯狂行为的充分理由?问题的简单演示:#includestructA{charbuf[512];interr;operatorchar*(){returnbuf;}operatorconstchar*()const{returnbuf;}operatorbool()const{return!err;}//explicitop

c++ - CMake "clang++ is not able compile a simple test program"(软呢帽 20)

所以我尝试安装clang+cmake来编译一个简单的C++程序,但出现以下错误:--TheCcompileridentificationisGNU4.8.3--TheCXXcompileridentificationisClang3.5.0--CheckforworkingCcompiler:/usr/bin/cc--CheckforworkingCcompiler:/usr/bin/cc--works--DetectingCcompilerABIinfo--DetectingCcompilerABIinfo-done--CheckforworkingCXXcompiler:/usr/

c++ - 排序 : Is this performance difference for real or am I doing something wrong?

我需要对很多由8个float组成的小数组进行排序。最初我使用的是std::sort但对其性能不满意,我尝试了由此生成的比较交换算法:http://pages.ripco.net/~jgamble/nw.html测试代码如下:templateboolPredDefault(constT&a,constT&b){returna>b;}templateboolPredDefaultReverse(constT&a,constT&b){returnavoidSort8(T*Data,bool(*pred)(constT&a,constT&b)=PredDefault){#defineCmp_S

c++ - Opencv,对 `cv::imread(??cv::String const&???, int)' 的 undefined reference

这个问题在这里已经有了答案:error:undefinedreferenceto`cv::imread(std::stringconst&,int)'(4个答案)Whatisanundefinedreference/unresolvedexternalsymbolerrorandhowdoIfixit?(38个答案)关闭5年前。我在QT+Opencv中有一个项目,代码可以正常工作,但我必须格式化窗口,现在我试图再次导入该项目,但出现了这个错误。对`cv::imread(cv::Stringconst&,int)'的undefinedreference在这一行中:mat=cv::imre

c++ - 调用 const 可变 lambda

为了简化测试用例,假设我有以下包装类:templatestructWrapper{decltype(auto)operator()()const{returnm_t();}decltype(auto)operator()(){returnm_t();}Tm_t;};templateautomake_wrapper(Tt){returnWrapper{t};}假设我包装了以下简单的仿函数返回引用:structFoo{int&operator()(){returnx;}constint&operator()()const{returnx;}intx;};在我的main函数中,我试图将Foo

c++ - 为什么T 'skips'的模板参数推导是数组元素的const,而函数参数是对T的const引用?

让我们考虑一下这些定义:/***fulltypeinformationwithtypeid***/templateclassType{};templatestd::stringtypeStr(){returntypeid(Type).name();}/***functiontemplateforparameterdeduction***/templatevoidfunc(constT&a){std::cout()()指向常量的指针如果执行以下语句:constinti=5,*ip=&i;func(ip);输出是:DeducedtypeforTis:4TypeI**PKi**E所以T实际上

c++ - 继承的构造函数和 "explicit is better than implicit"

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭7年前。Improvethisquestion良好编程风格的一个众所周知的原则是:“显式优于隐式”。继承的构造函数不是违背了这个原则吗?(包含基类的所有构造函数的单个using语句不是很明确,对吗?)

c++ - 构造函数何时调用 const-expr?

什么时候构造函数调用const-expr什么时候不是?在这个链接问题中Arethesevectordefinitions"constantinitialization"?构造函数不是const-expr,这就是vector未const初始化的原因。还有人可以更详细地解释该问题的答案吗? 最佳答案 您是在问何时可以在需要常量表达式的上下文中使用构造的结果?例如classA{constexprA(...){...};constexprintget(){...};...}constexprAa(...);std::arrayx{};换句话

c# - 如何将 C++/CLI 字符串转换为 const char*

我有一个C++/CLIDLL,我打算将其用作我的C#DLL和nativeC++客户端之间的适配器。我需要在两个方向上传递字符串。该适配器是使用VS2013编译的,但需要支持使用VS2008构建的客户端,因此我在API中使用constchar*。但是即使两者都是VS2013构建的,我所得到的也无法正常工作。我在其他地方找到了使用msclr\marshal.h的建议,因此我创建了:usingnamespacemsclr::interop;System::String^ToCliString(constchar*s){System::String^result=marshal_as(s);r

c++ - 为什么 std::is_constructible 在直接上下文中停止?

源自this话题。也与此有关topic.我的问题是为什么std::is_constructible在直接上下文中停止?我认为std::is_constructible的用户会期望它能够深入工作并给出准确的答案。有了这个直接的上下文,你可能会让std::is_constructible给你一个绿灯,只是在你实际执行它时得到一个硬编译器错误。这是否违背了std::is_constructible的最初目标和目的。现在,它对我来说基本上看起来没用。我想std::looks_constructible_at_first_sight是当前语义的更好名称:( 最佳答案