草庐IT

限定词

全部标签

c++ - 类成员限定名称查找

考虑以下代码片段:classA{intb[A::a];//1,errorvoidfoo(){intb=A::a;}//2,okstaticconstinta=5;}条款3.4.3.1/1(限定名称查找,类成员)说:Ifthenested-name-specifierofaqualified-idnominatesaclass,thenamespecifiedafterthenested-name-specifierislookedupinthescopeoftheclass(10.2)这意味着将查找//1和//2中嵌套名称说明符之后的名称a在类范围内。条款10.2(成员名称查找)说:1

c++ - add_lvalue_reference/add_rvalue_reference 和 cv 限定类型

cppreference.com关于std::add_lvalue_reference/std::add_rvalue_reference:IfTisanobjecttypeorafunctiontypethathasnocv-orref-qualifier,providesamembertypedeftypewhichisT&&,otherwisetypeisT.这是否意味着如果T是const或volatile则T不会转换为引用?如果不是,那么“没有cv限定符”是什么意思。 最佳答案 DoesitmeanthatifTiscons

c++ - const XX 丢弃限定符 [- fpermissive]

在下面的代码片段1中,mKnownSRList定义如下:std::vectormKnownSRList;我收到代码片段2中显示的编译错误。你能告诉我这段代码有什么问题吗?getTipcAddress()和compareTo函数的内容显示在下面的代码片段3和4中。CODESNIPPET1(标出编译错误)voidServiceRegistrarAPI::removeKnownSR(EndPointAddr&srEndPointAddr){autolast=std::remove_if(mKnownSRList.begin(),mKnownSRList.end(),[srEndPointAd

C++ 返回类型限定符天堂

实际上是hell。有人可以用简单的英语解释为什么以下部分有效吗?classHey;classBitmap{public:constHey*const&getHey(){returnhey;};//worksconstHey*&getHey2(){returnhey;};//errorC2440:'return':cannotconvertfrom'Hey*'to'constHey*&'private:Hey*hey;}; 最佳答案 你不能将const添加到一个指针上,它本身不是const的不止一种类型,因为这样你就可以填充一个con

c++ - 如何将 const 限定符与 decltype 一起使用?

如何将const限定符与decltype一起用于template-ed函数?当前GCCrejects以下:templateboolprocess(Itfirst,Itlast){returnstd::all_of(first,last,[](constdecltype(*first)&i)//^^^^^withoutconstitworksfine{returni%2==0;});}在lambda中使用i作为const引用是否合法/可能? 最佳答案 constdecltype(*first)&不起作用,因为decltype(*fir

c++ - 3.4.1 非限定名称查找

根据C++标准:-Thenamelookuprulesapplyuniformlytoallnames(includingtypedef-names(7.1.3),namespace-names(7.3),concept-names(14.9),concept-map-names(14.9.2),andclass-names(9.1))whereverthegrammarallowssuchnamesinthecontextdiscussedbyaparticularrule.在重载解析发生之前应用名称查找规则?一定有我不明白的原因。以下示例来自BookC++inaNutshell:-

c++ - 为什么 N3421 不提供 noexcept 限定词?

在N3421-MakingOperatorFunctorsgreater,std函数对象的新特化是:templatestructplus{templateautooperator()(T&&t,U&&u)const->decltype(std::forward(t)+std::forward(u));};代替templatestructplus{templateautooperator()(T&&t,U&&u)constnoexcept(noexcept(decltype(std::forward(t)+std::forward(u))(std::move(std::forward(t

c++ - 为什么删除此类型别名中的 const 限定符?

这个问题在这里已经有了答案:constantreferenceswithtypedefandtemplatesinc++(5个答案)关闭4年前。长话短说给定以下类型:structA{std::vectorvec;usingreference=std::iterator_traits::reference;usingconst_reference=constreference;};为什么reference==const_reference?为什么在第二个类型别名中删除了const限定符?请参阅godbold上的示例不应该编译。详情我有一个模板化类,它接受一堆迭代器(-types)作为模板

c++ - 函数声明中缺少 'virtual' 限定符

在浏览一些旧代码时,我遇到了类似于以下内容的内容:classBase{public:virtualintFunc();...};classDerived:publicBase{public:intFunc();//Missing'virtual'qualifier...};代码编译良好(MSVS2008),没有警告(级别4)并且按预期工作-Func是虚拟的,即使派生类中缺少虚拟限定符。现在,除了引起一些困惑之外,这段代码是否有任何危险,或者我是否应该全部更改它,添加virtual限定符? 最佳答案 virtual将被传递到派生类中的

用于命名空间限定的 C++ 预处理器 token 粘贴

我在使用gcc4.7.1(std=c++11)中的预处理器标记粘贴运算符时遇到问题。即,考虑以下代码://Createanameforaglobalmap(thisworks)#defineGLOBAL_MAP(name)g_map_##name//Thisworksfine//Now,namespacequalifythismap(thisfailstocompilewhenused)#defineNS_QUAL_GLOBAL_MAP(name)SomeNamespace::##GLOBAL_MAP(name)使用场景——首先是map定义:std::mapGLOBAL_MAP(my_