草庐IT

fno-implicit-templates

全部标签

c++ - "Name The Template Parameter"奇定义

template//whyisboolhere,classbooltype=bool.Aretheyequivalent?structif_{typedeftypenamettype;};templatestructif_//whatdoesthemean?{typedeftypenameutype;};代码来自一篇名为“命名模板参数”的文章。我无法理解both结构的定义。 最佳答案 编辑:首先移动最重要的部分:if_::type;//thisisintif_::type;//thisisdouble这很方便地定义了一个可以在编译时

c++ - 专门化成员 S::display 需要 ‘template<>’ 语法

我正在创建一个特征类来帮助我的程序。我有一个名为operations的模板类包含方法display和area.当我定义这些函数时,我得到了错误。他们在这里:error:specializingmember‘traits::operations::display’requires‘template’syntaxerror:specializingmember‘traits::operations::area’requires‘template’syntax如您所见,编译器要我插入template就在这些定义之前。但是当我这样做时,我会收到一大页错误。出了什么问题,我该如何解决?这是我的程

c++ - 在类型说明符中使用 "simple-template-id"

在C++11标准中,dcl.type.simple和dcl.type.elab部分声明类型说明符可以包括simple-template-编号。另一方面,根据temp.names部分,simple-template-id可以表示函数模板特化。真的可以使用函数模板特化来指定类型吗? 最佳答案 7.1.6.2/2Theothersimple-type-specifiersspecifyeitherapreviously-declareduser-definedtypeoroneofthefundamentaltypes(3.9.1).强调

c++ - 为什么bitset要用template来实现?

要定义一个16位的位集,就像这样:std::bitsetbs(0x123);如果让我设计一个bitset类,我大概会这样:mine::bitsetbs(16,0x123);std::bitset是由模板实现的有什么原因吗?这是我们应该在某些情况下应用的好模式吗? 最佳答案 Isthereanyreasonthatstd::bitsetisimplementedbytemplate?Isthisagoodpatternthatweshouldapplyinsomesituations?因为std::bitset被设计成一个静态位集。在

c++ - 错误 : Use of class template requires template argument list

当我尝试运行我的程序时,此错误显示为“errorC2955:'FOURTEEN':useofclasstemplaterequirestemplateargumentlist”#includeusingnamespacestd;templateclassFOURTEEN{private:Ta[n];public:voidReadData();voidDisplayData();};voidFOURTEEN::ReadData(){for(inti=0;i>a.[i];}voidFOURTEEN::DisplayData(){for(inti=0;i>a.[i]P;//Readdatai

c++ - 我可以将 `extern template` 放入头文件中吗?

在头文件中放一个外部模板,然后在单元编译文件中显式模板实例化有效吗?例如在g++的编译示例中,这是为了避免nothing的实例化吗?两次?为什么没有人这样写而更喜欢复制externtemplate每个.cpp文件中的行?A.hpp:#ifndefHEADERC_A#defineHEADERC_Atemplatestructnothing{};externtemplatestructnothing;#endifA.cpp:#include"A.hpp"templatestructnothing;ma​​in.cpp:#include"A.hpp"#includeintmain(){not

c++ - 如何与 "template using"定义的模板(别名)类成为 friend ?

类B想和每个人成为friendC.我正在努力寻找解决方法。只要我不添加有问题的行,下面是成功编译的完整代码。#includeusingnamespacestd;enumEN{EN1,EN2};templateclassC{public:C(){std::coutclassB{templateusingCT=C;//templatefriendclassCT;//ct;}};intmain(){B::test();return0;}这是我尝试过的(全部失败):-templatefriendclassC;templatefriendclassCT;templatefriendclassCT

c++ - C++ 模板的部分特化 : template parameter not deducible

下面的代码工作正常:templateclassFib{};templateclassFib{};但是下面的代码显示错误为:Error:templateparametersnotdeducibleinpartialspecialization:templateclassFib{};templateclassFib{};你能解释一下这种行为的原因吗? 最佳答案 我相信您只是缺少部分特化的正确语法:templateclassFib{};templateclassFib{};模板上的第一个参数是类型,而第二个只是一个常量值。

c++ - clang、std::function 和 -fno-rtti

我在Windows上通过clang-cl使用Clang5,在使用std::function-fno-rtti)时遇到问题.这是我无法编译的示例:#includevoidfoo(std::functionra2){}intmain(){autobar=[](){};foo(bar);returnEXIT_SUCCESS;}命令行:clang-cltest.cpp-Xclang-fno-rtti错误是:C:\ProgramFiles(x86)\MicrosoftVisualStudio\Preview\Community\VC\Tools\MSVC\14.13.26128\include\

c++ - template<class = enable_if_t<...>> 做什么?

我一直在阅读STL文件,以学习格式化代码的更好方法,并学习提高效率的技巧。我一直在阅读线程文件,但我无法弄清楚某些代码的作用。template,thread>::value>>explicitthread(_Fn&&_Fx,_Args&&..._Ax){//constructwith_Fx(_Ax...)...}std::enable_if_t是templateusingenable_if_t=typenameenable_if::type;templatestructenable_if{//typeis_Tyfor_Testusingtype=_Ty;};该代码在thread和str