草庐IT

ENABLE_LOCAL_OSAUTH

全部标签

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++ - enable_if'ed 模板化模板构造函数的类型签名?

我通常先声明我的类和模板,然后再定义它们的方法(当然是在同一个头文件中)。我只是觉得这样更容易阅读。好吧,我遇到过这样一种情况,我无法找出在类外定义中使用的有效类型签名。这是我正在做的一个简化示例,它说明了问题:templatestructFoo{Foo(Ta,Tb);template>>Foo(Iteratorfirst,Iteratorlast);};templateFoo::Foo(Ta,Tb){...}templatetemplateFoo::Foo(Uf,Ul){...}我在WHAT_GOES_HERE槽中尝试了很多方法来尝试获得匹配的签名,但我一直失败。我需要enable_

c++ - 错误 C4703 : potentially uninitialized local pointer variable 'pNamesPtr' used

我正在做一个加密项目,在尝试编译程序时遇到了以下错误。main.cpp(520):errorC4703:potentiallyuninitializedlocalpointervariable'pNamesPtr'used==========Build:0succeeded,1failed,0up-to-date,0skipped==========DLLNAMES[i].UsedAlready=0;}*dwOutSize=(DWORD)pNamesPtr-(DWORD)pBuffer;//*有人可以帮我解决这个错误吗?您是否需要更多代码才能得到好的答案?

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++ - 使用 enable_if 专门化模板方法

我正在编写一个模板类,它存储一个std::function以便稍后调用它。这是简化的代码:templatestructTest{voidcall(Ttype){function(type);}std::functionfunction;};问题是这个模板不能为void类型编译,因为voidcall(voidtype)变得未定义。将它专门用于void类型并不能缓解问题,因为templatevoidTest::call(void){function();}仍然与call(TType)的声明不兼容。因此,利用C++11的新特性,我尝试了std::enable_if:typenamestd::

C++ 局部变量和线程(非 thread_local)

局部数组和线程交互的C++98和C++11内存模型是什么?我不是指的是C++11thread_local关键字,它与全局变量和静态变量有关。相反,我想找出在编译时分配的数组线程的保证行为是什么。我所说的编译时指的是“intarray[100]”,这与使用new[]关键字进行分配不同。我不是指静态变量。例如,假设我有以下结构/类:structxyz{intarray[100];};和以下函数:voidfn(intx){xyzdog;for(inti=0;i从多个线程调用fn()安全吗?看起来C++的内存模型是:所有局部非静态变量和数组都分配在栈上,每个线程都有自己的栈。这是真的吗(即,这

用于非类型模板参数的 c++ enable_if

我对部分模板特化有点困惑...我有一些代码依赖于算术数据类型T和小整数DIM。我希望能够为不同的DIM值指定不同的类方法。使用部分模板特化的不可能让我探索enable_if。这正是我所需要的……除了我希望它返回一个数字而不是一个类型。我怎样才能做到这一点?下面的代码应该说明我想要什么。#include#include#includetemplateclassfoo{public:Tfunction();};templateTfoo::value>::function(){//dosomethingreturn1.0;}templateTfoo::value>::function(){/

c++ - 如何将 enable_if 用于互斥的非成员函数模板?

我正在尝试编写非成员运算符函数模板,例如:#includetemplateclassMyType;templateautooperator==(MyTypeconst&l,MyTypeconst&r)->decltype(std::declval()==std::declval()){/*...*/}但是当我尝试处理l和r的长度不同时:template::type>autooperator==(MyTypeconst&l,MyTypeconst&r)->decltype(std::declval()==std::declval()){/*...*/}templateLu)>::type

c++ - 迭代器或指针的 std::enable_if 或 SFINAE

我想为MyClass编写一个带有参数的构造函数,并且我希望仅当参数是一个pointer或iterator(具有iterator_traits的东西)。如何实现? 最佳答案 遗憾的是,没有标准的方法来检测类是否为Iterator模型。最简单的检查是*it和++it在语法上都是有效的;您可以使用标准SFINAE技术执行此操作:template(),void(),++std::declval(),void())>MyClass(T);考虑到24.2.2:2中的Iterator要求:templatetypenamestd::enable_i

c++ - enable_if 有条件地包含成员函数

我有一个模板类,它的类型是迭代器。我想根据模板参数的iterator_category启用/禁用特定成员函数。特别是,我想启用operator--如果模板参数是双向迭代器。我的尝试是这样的:typenamestd::enable_if::value,MyType&>::typeoperator--(){//doworkreturn*this;}Clang告诉我(大致):error:notypenamed'type'in'std::__1::enable_if';'enable_if'cannotbeusedtodisablethisdeclaration有没有办法完成我正在尝试的事情?