草庐IT

template_directory

全部标签

c++ - CRTP和template模板参数限制

我正在尝试使用CRTP,但我对以下代码无法编译的原因感到困惑。templateclassCBase>structComponentX:publicCBase{//ThisdoesNOTcompile};templateclassCBase>structComponentY:publicCBase{//Thisdoescompile};你知道在CRTP的情况下模板模板参数是否有一些限制吗? 最佳答案 类模板名称代表“当前特化”(即它是一个注入(inject)的类名)仅在打开{之后类模板定义,在其范围内。在此之前,它是一个模板名称。所以

c++ - 错误 C2823 : a typedef template is illegal - function pointer

我想使用模板定义一个函数指针类型。但是,VS2013我认为“typedef模板是非法的”。我想写这样的东西:templatetypedefvoid(*FuncPtr)(void*object,SD*data);不幸的是,这无法编译。我想保持简短。基本上我需要为一个函数指针定义一个类型,它的参数是一个模板类。 最佳答案 自C++11起,您可以使用using关键字的效果非常像typedef,它允许模板:templateusingFuncPtr=void(*)(void*,SD*);在此之前,您必须将模板与typedef分开:templa

c++ - "unspecialized class template can' t be used as a template argument”是什么意思?

我有一个名为AbstractRManagers的类,我想从一个单例模板类Singleton继承,但是abstractRmanager需要成为一个模板类我遇到了一些没有用的奇怪错误代码,我已经尝试查找它但是没运气。templateclassAbstractRManagers:publicSingleton{errorC3203:'AbstractRManagers':unspecializedclasstemplatecan'tbeusedasatemplateargumentfortemplateparameter'Type',expectedarealtype

ssh报错:no such identity: /xxx/xxx/.ssh/id_rsa: No such file or directory解决方案

ssh报错:nosuchidentity:/xxx/xxx/.ssh/id_rsa:Nosuchfileordirectory.Permissiondenied(publickey)解决方案最近在使用ssh方式连接公司跳板机时报错:Warning:Permanentlyadded'xxx'(ECDSA)tothelistofknownhosts.nosuchidentity:/xxx/xxx/.ssh/id_rsa:Nosuchfileordirectorynosuchidentity:/xxx/xxx/.ssh/id_dsa:Nosuchfileordirectorynosuchidenti

为什么 *ngif不使用ng-template?

我在模板中有一个条件如下:Section{{seat?.section}},Row{{seat?.row}},Seatnumber{{seat?.seatNo}}我有包含的数据集row和seatNo,但似乎没有在模板中打印。这里有什么问题?看答案在这里阅读文档https://angular.io/guide/structural-directives尤其是给{{hero.name}}星号是“句法糖”,对于更复杂的东西。在内部,AngularDesugars分为两个阶段。首先,它将*ngif=“...”转换为模板属性,template=“ngif...”,如这样。{{hero.name}}然后,

解决Git 报错:fatal: destination path ‘xxx‘ already exists and is not an empty directory

一、背景拿到开发的Git地址,然后Git clone的时候,检测不出东西,只有一个.git目录,实际无东西。 二、解决方案方案一、删除.git文件可手动删除,或执行下面命令rm-rf.git然后再执行检出命令gitclonehttps://git.xxx.com/xxx.git方案二、新建目录再重新检出熟悉linux命令都知道rm-rf.git命令会删除当前目录的git记录,如果没有把握的话,最好还是新建一个目录,比如xxx目录,命令如下:mkdirxxxcdxxx然后再执行检出命令gitclonehttps://git.xxx.com/xxx.git方案三、可能没有master分支,切换其他

c++ - gcc-4.9.2 : non-type template parameter

我在gcc-4.9.2上有一个奇怪的编译错误,相同的代码在其他编译器上工作,比如gcc-4.8或我能找到的任何clang。问题与non-typetemplate-arguments有关.所以考虑一下:#include#includeinttemplateParam;templatestructTestTemplate{intvalue(){}};templateintTestTemplate::value(){returntemplateParam;}TestTemplatetestVariable;intmain(){std::cout我在gcc-4.9.2中遇到以下错误:prog.

C++ 模板 : Partial Template Specifications and Friend Classes

是否有可能以某种方式使部分模板规范成为友元类?IE。考虑你有以下模板类templateclassX{Tt;};现在你有了部分特化,例如,指针templateclassX{T*t;};我想要完成的是每一个可能的X是X的好友类对于任何S.IE。X应该是X的friend.当然,我想到了X中的常用模板友元声明:templateclassX{templatefriendclassX;}但是,这不会编译,g++告诉我:test4.cpp:34:15:错误:'templateclassX的特化'必须出现在命名空间范围内test4.cpp:34:21:错误:部分特化'X'声明'friend'这根本不可

c++ - constexpr 与 std::array - "Non-type template argument is not a constant expression"

这个问题在这里已经有了答案:Errorusingaconstexprasatemplateparameterwithinthesameclass(2个答案)关闭9年前。我正在尝试实现以下内容:#include#includeclassClass2{};classClass1{public:staticconstexpruint8_tGetMax(){return5;}staticconstexpruint8_tGetMin(){return0;}staticconstexpruint8_tGetCount(){returnGetMax()-GetMin()+1;}private:std

c++ - 依赖类型 : Template argument deduction failed

在我的代码中,我使用了模板化图像类Image结合std::shared_ptr.这些图像指针应该传递给各种图像处理函数,其中一些函数与图像类型无关。考虑以下Image的定义和两个处理函数function1()和function2().#includetemplatestructImage{typedefstd::shared_ptr>Ptr;};templatevoidfunction1(typenameImage::Ptrimage){}templatevoidfunction2(std::shared_ptr>image){}同时function1()和function2()实际上