weak-template-vtables
全部标签 我尝试编写一个IsLast类型特征来检查给定类型是否是std::tuple中的最后一个类型,但下面的代码无法编译。我知道如何绕过它,但我很好奇为什么编译器不喜欢它。我想一定有一些我不知道的关于可变参数模板特化的规则。代码位于:https://godbolt.org/g/nXdodx错误信息:error:implicitinstantiationofundefinedtemplate'IsLast,int>,int>'还有关于特化声明的警告:warning:classtemplatepartialspecializationcontainstemplateparametersthatca
如何使用std::weak_ptr作为std::map的关键如下代码所示?#include#includeintmain(){std::map,bool>myMap;std::shared_ptrsharedptr(newint(5));std::weak_ptrweakptr=sharedptr;myMap[weakptr]=true;return0;}上面的程序没有构建,尝试编译它会给出许多错误消息,例如:1>C:\ProgramFiles(x86)\MicrosoftVisualStudio10.0\VC\include\xfunctional(125):errorC2784:'
创建一个临时的shared_ptr只是为了查看weak_ptr是否指向一个有效的对象似乎有点低效。我什至不想访问该对象。这是因为我有一个从shared_ptrvector返回weak_ptr的函数,如果它返回一个空的weak_ptr那么这意味着该对象不存在该GUID。所以我只是在测试一个对象是否存在。有没有另一种方法可以在不创建shared_ptr的情况下检查weak_ptr是否为空? 最佳答案 您可以使用expired()成员函数。 关于c++-我是否必须使用weak_ptr.lock
通过以下代码我得到了警告:warning:specializationof‘templatestructstd::iterator_traits’indifferentnamespace[-fpermissive]templateclassstd::iterator_traits{public:typedefWorddifference_type;typedefWordvalue_type;typedefToken_ptrpointer;typedefWord&reference;typedefstd::bidirectional_iterator_tagiterator_catego
我做了如下程序#include#includetemplatestructClass{templatevoiddisplay(){std::coutvoidfunc(Classk){k.display();}intmain(){Classd;func(d);}上面的程序没有编译因为display()是一个模板成员函数,所以.template的资格之前display()必须完成。我说得对吗?但是当我制作下面的程序时#include#includetemplateclassmyClass{Tdummy;/*******/public:templatevoidfunc(myClassobj)
我尝试使用CuriouslyRecurringTemplatePattern(CRTP)并提供额外的类型参数:templateclassBase{Int*i;Float*f;};...classA:publicBase{};这可能是一个错误,更合适的父类(superclass)是Base--尽管这种参数顺序不匹配不是那么明显。如果我可以在typedef中使用名称参数的含义,这个错误会更容易看到:templateclassBase{typenameSubclass::Int_t*i;//error:invaliduseofincompletetype‘classA’typenameSub
这是测试代码templatevoidf(){Tt;t.f(0);//compilesevenwithoutthe"template"keyword,whatamImissing?}classabc{public:templatevoidf(int){}};intmain(){f();}我正在使用g++4.4.6。谢谢P.S:我已经大大编辑了我的问题。请不要介意。编辑:我向EDG的人问了这个问题,这是MikeHerrick不得不说的Wedodiagnosethisasanerrorin--strictmodeaswellasanymodethatenablesdependentnamel
作为大型程序的特征类的一部分,我尝试创建一个静态类变量,该变量可能具有不同的值,具体取决于实例化封闭类模板的类型。我已经简化了相关代码以生成我正在谈论的内容的简单示例:#include#include#includetemplatestructFoo;templatestructFoo::value>::type>{staticstd::stringmessage;};templatestructFoo::value>::type>{staticstd::stringmessage;};templatestd::stringFoo::message;对于GCC4.6,这会产生一个编译器
考虑这个例子(alsoavailableonwandbox):templateclass>voidtest(){}templatestructX{};正在尝试实例化test()在clang++4.0(trunk)导致编译错误:error:nomatchingfunctionforcallto'test'test();^~~~~~~note:candidatetemplateignored:invalidexplicitly-specifiedargumentfor1sttemplateparametervoidtest(){}我最初的假设/直觉是test可用于匹配任何template具
我有一个由Graph和Node类实现的有向无环图。每个节点都有一个指向子节点的指针列表和一个指向父节点的指针列表。我最近添加了父级,因为一些算法需要快速访问父级列表,而且图很小,每个节点只有很少的连接,所以没有内存问题。子列表使用std::shared_ptr以便节点至少在它们有父节点时保留在内存中。但是我不希望节点拥有它的父节点,所以我使用weak_ptr作为指向父节点的指针。但是后来算法出了问题。算法必须从weak_ptr创建一个新的shared_ptr,所以我不能直接使用operator==,并且使用标准函数如std::find()需要编写一个调用my_weak_ptr.lock