草庐IT

fno-implicit-templates

全部标签

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,这会产生一个编译器

c++ - C++1 7's deduced ` auto` 非类型 `template` 参数是否可以使用显式非类型参数模式匹配模板?

考虑这个例子(alsoavailableonwandbox):templateclass>voidtest(){}templatestructX{};正在尝试实例化test()在clang++4.0(trunk)导致编译错误:error:nomatchingfunctionforcallto'test'test();^~~~~~~note:candidatetemplateignored:invalidexplicitly-specifiedargumentfor1sttemplateparametervoidtest(){}我最初的假设/直觉是test可用于匹配任何template具

c++ - 右值引用 : Why aren't rvalues implicitly moved?

在关于C++右值引用(http://www.artima.com/cppsource/rvalue.html)的Artima文章中有这样的话:这就是为什么在向下传递到基类时必须说move(x)而不是只说x的原因。这是移动语义的一个关键安全特性,旨在防止从某个命名变量意外移动两次。我想不出这样的双招可以执行的情况。你能举个例子吗?换句话说,如果T&&的所有成员都是右值引用而不仅仅是引用,会出现什么问题? 最佳答案 考虑这个场景:voidfoo(std::stringx){}voidbar(std::stringy){}voidtest

c++ - "Template argument for template template parameter must be a class template or type alias template"

templatestructList{};templateclass>structListHelper;templatestructListHelper>{};^/*Error:Templateargumentfortemplatetemplateparametermustbeaclasstemplateortypealiastemplate*/怎么了?我正在使用clang++SVN。 最佳答案 您有一个模板模板参数。您必须传递一个模板作为其参数。您改为将模板实例化作为其参数传递-这是一个具体类,而不是模板(其所有参数均已绑定(bi

c++ - 专门化成员函数时出现 "too many template-parameter-lists"错误

我想像这样在模板类中定义一些模板成员方法:templateclassCallSometing{public:voidcall(TtObj);//1sttemplatevoidcall(TtObj,AaObj);//2ndtemplatetemplatevoidcall(TtObj,AaObj,BbObj);//3rd};templatevoidCallSometing::call(TtObj){std::couttemplatevoidCallSometing::call(TtObj,AaObj){std::couttemplatetemplatevoidCallSometing::c