草庐IT

fno-implicit-templates

全部标签

c++ - template<> 用于成员枚举的显式特化

根据17.7.3[temp.expl.spec]第5段(N4659),...Membersofanexplicitlyspecializedclasstemplatearedefinedinthesamemannerasmembersofnormalclasses,andnotusingthetemplatesyntax.Thesameistruewhendefiningamemberofanexplicitlyspecializedmemberclass.However,templateisusedindefiningamemberofanexplicitlyspecializedm

c++ - 想要 : a C++ template idea to catch an issue, 但在编译时?

我们有一个常量结构数组,像这样:staticconstSettingsSuT_table[]={{5,1},{1,2},{1,1},etc};结构如下:size_bytes:num_items:其他“元数据”成员所以“总大小”是单个元素的size_bytes*num_items。所有这些信息都在const数组中,在编译时可用。但是,请注意,_table的总大小与EEPROM本身的大小无关。_table不镜像EEPROM,它只描述了布局、用途和我们需要的其他“元数据”类型的信息。但是,您可以使用此元数据来确定我们正在使用的EEPROM的数量。数组简单地描述了存储在外部EEPROM中的数据

c++ - 错误 C2995 : function template has already been defined

此代码产生17错误C2995:函数模板已被定义;在添加#include"set.h"header之前存在一组单独的错误。有一个与此关联的私有(private).cpp和.h文件。/**File:private/set.cpp*LastmodifiedonThuJun1109:34:082009byeroberts*-----------------------------------------------------*Thisfilecontainstheimplementationoftheset.hinterface.*BecauseofthewayC++compilestemp

c++ - 两阶段查找 : is it possible to easily mix inheritence and templates

简介:C++标准区分依赖模板参数的符号名称和不依赖模板参数的名称,这称为两阶段名称查找(参见here)。定义模板时,会尽快解析非相关名称。另一方面,从属名称仅在模板实例化时解析。示例:templatestructBase{typedefTtype;staticconstintn=3;virtualintf()=0;intf(intx){returnx*2;}};//doesn'tcompile!templatestructDerived:Base{typefield;//Thecompilerdoesn'tknowBase::typeyet!intf(){returnn;}//thec

c++ - VS 编译警告 : result of 32-bit shift implicitly converted to 64 bits

VisualStudio2013发出恼人的(看似无关紧要的)编译警告:#include#definePRECISION16uint64_thi=0;for(uint8_ti=0;i这是编译警告:warningC4334:'改1好像解决了至1.所以我一直在尝试找出1中可能出现的问题.显然,如果i>=PRECISION,那么左移操作将产生未定义的行为。但是,变量i不超过PRECISION-1的值.此外,即使我们假设编译器无法推断出这个事实,我也看不出这个编译警告与左移操作数导致的潜在未定义行为有什么关系。也许它假定PRECISION-1-i的无符号值可以大于31。但是我应该如何告诉编译器它

c++ - SFINAE 优雅地检查 "template template class"(在模板参数中)

如何在模板参数中检查模板模板类的类型?例子B和C是模板类。我想创建一个类D那可以是D或D.只有D有D::f().这是我的解决方法(demo)。它有效。#includeusingnamespacestd;classDummy{};templateclassB{};templateclassC{};templateclassBC>classD{//f()isinstantiatedonlyif"BC"=="B"public:template>statictypenamestd::enable_if>::value,void>::typef(){}//^#1};intmain(){D::f(

c++ - 警告 C4661 :no suitable definition provided for explicit template instantiation request

我写了一个类模板并在不同的DLL中使用它,所以希望隐藏部分实现。为此,我使用“模板实例化”,但导出它,像这样,这里是头文件:#include#includeusingnamespacestd;templateclass__declspec(dllexport)Templated{public:Templated();};template__declspec(dllexport)Templated;intmain(){cout并且定义在单独的文件(.cpp)中templateTemplated::Templated(){}templateTemplated;我的问题是我收到警告,即使实例

c++ - "typename"和 "template"关键字 : are they really necessary?

编译c++模板代码时,这个站点上有很多问题。此类问题最常见的解决方案之一是在程序代码的正确位置添加typename(以及不太常见的template)关键字:templateclassBase{public:typedefcharSomeType;templatevoidSomeMethod(SomeType&v){//...}};templateclassDerived:publicBase{public:voidMethod(){typenameBase::SomeTypex;//^^^^^^^^this->templateSomeMethod(x);//^^^^^^^^}};是否有

C++ 模板 : cannot match the last template in variadic class template

我正在学习C++11可变参数模板并创建了一个模板结构来计算给定列表的最大数量并尝试了:#include#includetemplatestructmax:std::integral_constantb?max::value:max::value)>{};templatestructmax:std::integral_constantb?max::value:max::value)>{};templatestructmax:std::integral_constant{};intmain(){std::cout::value但是g++提示:test.cc:7:58:error:wrong

c++ - 析构函数 : triviality vs implicit definition

根据我对标准的理解,普通析构函数是一种隐式声明的析构函数,其类只有基本和非静态成员以及普通析构函数。鉴于此定义的递归性,在我看来,唯一的“递归停止”条件是找到具有非隐式声明的析构函数(即用户声明的)的基类或非静态成员。如果那是对的,那应该意味着一个普通的析构函数是一个“不需要做任何事情”的析构函数,因此它将被声明(隐式地)但不被定义。换句话说:根据标准定义,隐式定义析构函数(即“它做某事”)不能是微不足道的说法是否正确?很抱歉提出这种愚蠢的问题,但我想澄清一下我的想法...... 最佳答案 没有。隐式定义的平凡析构函数根据定义是平凡