草庐IT

nuclei-templates

全部标签

c++ - 在没有括号的宏中使用逗号 : How can I mix and match with a template?

考虑一个简单的宏:#defineECHO(x)xECHO(foo(1,2))这会产生我们期望的准确输出:foo(1,2)上面的例子之所以有效,是因为预处理器识别了与函数调用相邻的括号。现在考虑如果我使用模板而不是函数调用会发生什么:ECHO(template)这会导致错误,因为预处理器会解释template和bool>作为宏的两个单独参数。预处理器无法识别范围!有没有办法在宏中使用这样的模板? 最佳答案 #defineCOMMA,ECHO(template)有点痛,但有效。FWIW,如果参数的语法允许(),则不需要替换,例如,ECH

c++ - 链接器错误 'unresolved external symbol' : working with templates

我有一个基于模板的类[Allotter.h&Allotter.cpp]:templateclassAllotter{public:Allotter();quint32getAllotment(allotType*);boolremoveAllotment(quint32,intauto_destruct=0);private:QVector>indexReg;intinit_topIndex;};它的用法如[ActiveListener.h&ActiveListener.cpp]所示:classActiveListener:publicQObject{Q_OBJECTpublic:Ac

c++ - "if the context from which the specialization is referenced depends on a template parameter"是什么意思?

根据C++17标准,[temp.point]/4,强调我的,Foraclasstemplatespecialization,aclassmembertemplatespecialization,oraspecializationforaclassmemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecialization,ifthecontextfromwhichthespecializationisrefere

c++ - "templating"命名空间

我想构建这样的东西:File1:templatenamespacemyNamespace{classmyClass1{myClass1(Vectorv){...}}}File2:templatenamespacemyNamespace{classmyClass2{myClass2(Vectorv){...}}}当然这是不可能的,因为你不能模板命名空间。相反,我可以使用结构而不是命名空间,但这样我就无法将命名空间函数分布到多个文件中。这样的问题有什么解决办法吗?PS:我知道我可以对类进行模板化,但是我必须在创建新类时指定要使用的vector类型。 最佳答案

C++ 模板部分特化 : Why cant I match the last type in variadic-template?

我尝试编写一个IsLast类型特征来检查给定类型是否是std::tuple中的最后一个类型,但下面的代码无法编译。我知道如何绕过它,但我很好奇为什么编译器不喜欢它。我想一定有一些我不知道的关于可变参数模板特化的规则。代码位于:https://godbolt.org/g/nXdodx错误信息:error:implicitinstantiationofundefinedtemplate'IsLast,int>,int>'还有关于特化声明的警告:warning:classtemplatepartialspecializationcontainstemplateparametersthatca

c++ - 警告 : specialization of template in different namespace

通过以下代码我得到了警告:warning:specializationof‘templatestructstd::iterator_traits’indifferentnamespace[-fpermissive]templateclassstd::iterator_traits{public:typedefWorddifference_type;typedefWordvalue_type;typedefToken_ptrpointer;typedefWord&reference;typedefstd::bidirectional_iterator_tagiterator_catego

c++ - 我们什么时候需要 .template 结构

我做了如下程序#include#includetemplatestructClass{templatevoiddisplay(){std::coutvoidfunc(Classk){k.display();}intmain(){Classd;func(d);}上面的程序没有编译因为display()是一个模板成员函数,所以.template的资格之前display()必须完成。我说得对吗?但是当我制作下面的程序时#include#includetemplateclassmyClass{Tdummy;/*******/public:templatevoidfunc(myClassobj)

c++ - 将 Curiously Recurring Template Pattern (CRTP) 与其他类型参数一起使用

我尝试使用CuriouslyRecurringTemplatePattern(CRTP)并提供额外的类型参数:templateclassBase{Int*i;Float*f;};...classA:publicBase{};这可能是一个错误,更合适的父类(superclass)是Base--尽管这种参数顺序不匹配不是那么明显。如果我可以在typedef中使用名称参数的含义,这个错误会更容易看到:templateclassBase{typenameSubclass::Int_t*i;//error:invaliduseofincompletetype‘classA’typenameSub

c++ - "template"不需要关键字? [gcc/clang/Comeau 错误?]

这是测试代码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

c++ - G++ 编译器错误或错误代码? : "template definition of non-template"

作为大型程序的特征类的一部分,我尝试创建一个静态类变量,该变量可能具有不同的值,具体取决于实例化封闭类模板的类型。我已经简化了相关代码以生成我正在谈论的内容的简单示例:#include#include#includetemplatestructFoo;templatestructFoo::value>::type>{staticstd::stringmessage;};templatestructFoo::value>::type>{staticstd::stringmessage;};templatestd::stringFoo::message;对于GCC4.6,这会产生一个编译器