草庐IT

claim_template

全部标签

c++ - 嵌套命名空间 : where should default template arguments go? 中模板类的前向声明

我在嵌套命名空间中有一个模板类的前向声明namespacen1{namespacen2{templatestructA;}usingn2::A;}接着是一个定义,实际上它在不同的文件中,中间有一些东西:structX{};namespacen1{namespacen2{templatestructA{};}usingn2::A;}那么以下总是可以的:n1::n2::Aa;但是这个捷径n1::Aa;在clang中给出编译错误error:toofewtemplateargumentsforclasstemplate'A'除非我删除前向声明;g++两者都接受。clang似乎保留在第一个不包含

c++ - g++ 错误 : specialization after instantiation (template class as friend)

考虑以下C++代码:templateclassSingleton{};classConcreteSingleton:publicSingleton{templatefriendclassSingleton;};intmain(){}Singleton应该是ConcreteSingleton的friend:它适用于Microsoft的可视化C++编译器。但是,我不能用g++4.8.4编译它。错误是:error:specializationof‘Singleton’afterinstantiationtemplatefriendclassSingleton;有什么办法可以解决吗?

C++ template-id 不匹配任何模板?

我用模板和特化写了一个简单的代码:#includetemplateintHelloFunction(constT&a){std::coutintHelloFunction(constchar*&a){std::cout我认为char*特化是正确的,但是g++报告:D:\work\test\HelloCpp\main.cpp:11:5:error:template-id'HelloFunction'for'intHelloFunction(constchar*&)'doesnotmatchanytemplatedeclaration请帮我找出错误。 最佳答案

c++ - 错误 : C2988: unrecognizable template declaration/definition

我的两个模板的标题中出现错误。两者都有类似的声明和定义如下:templatevoidsetVideoCodecOption(T1AVCodecContext::*option,T2(CR2CVideoCodecSettings::*f)()const);templatevoidEncoderPrivate::setVideoCodecOption(T1AVCodecContext::*option,(CR2CVideoCodecSettings::*f)()const){T2value=(m_videoSettings.*f)();if(value!=-1){m_videoCodecC

c++ - 模板特化站点报告 "too few template-parameter-lists"错误

代码某处有错误,但我不知道如何解决。它说“模板参数列表太少”。我不明白哪个是错误的。代码如下:#if!defined(VECTOR_H_INCLUDED)#defineVECTOR_H_INCLUDED#include//forsize_tnamespaceVec{classVector_base{public:explicitVector_base(){}};templateclassVector:publicVector_base{typedefVectorME;explicitVector(T,T,T);doubledot(constME&v)const;T&operator[]

C++1y/14 : auto variable templates?

下面的C++1y/C++14程序格式错误吗?templateconstexprautoX=42;intmain(){static_assert(X==42,"");}为什么/为什么不?Clangtrunk提示说:error:invalidoperandstobinaryexpression('auto'and'int') 最佳答案 这是clang中的一个错误,现在已修复:http://llvm.org/bugs/show_bug.cgi?id=19152 关于C++1y/14:autov

c++ - std::map 和 -fno-implicit-templates

我正在尝试使用g++4.4进行编译并链接一个使用STL的简单程序。我正在尝试使用-fno-implicit-templates来做到这一点,因此必须显式实例化所有模板。我不明白为什么此代码有效:#include//templateclassstd::map;templateclassstd::_Rb_tree,std::_Select1st>,std::less,std::allocator>>;intmain(){std::maptable;return0;}我希望这个程序需要这一行:templateclassstd::map;,但是该行不会使程序链接。std::_Rb_treeli

C++:专门化成员需要 «template<>» 语法

我做错了什么?templateclassBinder{public:staticstd::vector*>all;Node*from;Node*to;Binder(Node*fnode,Node*tonode){from=fnode;to=tonode;Binder::all.push_back(this);}};std::vector*>Binder::all=std::vector*>();//hereitis谢谢。 最佳答案 静态成员的定义被编译器解释为一个特化(实际上,它是一个特化:你给出了一个特定于T=int的声明)。这可

c++ - template-parameter-list of template parameter 是什么意思

引用3.3.9/1中的一句话:Thedeclarativeregionofthenameofatemplateparameterofatemplatetemplate-parameteristhesmallesttemplate-parameter-listinwhichthenamewasintroduced.你能举个例子来理解上面的定义吗?我也想知道模板参数的模板参数列表是什么意思?示例会有所帮助。 最佳答案 template//thedeclarativeregionendshereclassq//hencethenamema

c++ - 如何将 `std::array` 用作 `template<typename> class` 形式的模板参数?

请考虑以下tree类templateclassTuple>classtree{private:Tm_value;Tuplem_children;};templateusingstatic_tree=tree>;定义不明确。std::array不是Tuple的合适模板参数.我假设static_tree的意图清楚了。我们可以做类似的事情templatestructhelper{templateusingtype=std::array;};templateusingstatic_tree=tree::templatetype>;没有helper还有其他选择吗?类(class)?