草庐IT

weak-template-vtables

全部标签

c++ - "<vtable for A+16>"是什么意思?

这是我的代码。我只是想看看virtualinherit的内存布局。#includeusingnamespacestd;classA{private:inta;public:virtualvoidprint()const{cout然后在gdb中,我用papb输出是(gdb)pa$1={_vptr.A=0x400b40,a=0}(gdb)pb$2={={_vptr.A=0x400b18,a=4196384},membersofB:_vptr.B=0x400af8,b=0}(gdb)我知道_vptr.A和_vptr.B的含义,但我不明白B+24或A+16的vtable是什么意思。感谢您的回答

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++ - 构造一个 constexpr std::weak_ptr

根据std::weak_ptr文档可以构造一个constexprweak_ptr:#includeconstexprweak_ptrfoo{};但是,使用clang尝试此操作会产生编译错误,提示constexpr变量不能具有非文字类型'conststd::weak_ptr',这是因为weak_ptr有一个用户提供的析构函数。(确实如此,查看libc++header)我的问题是,这是一个libc++错误,还是做constexprweak_ptr只是没有意义并且拥有constexpr默认构造函数是一个错误?我可以期待它在未来发挥作用吗? 最佳答案

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++ - weak_ptr 和父子循环依赖

我目前有类似以下内容:classParent{//justasinglechild...forsakeofsimplicity//nootherclassholdsashared_ptrreferencetochildshared_ptr_child;System*getSystem(){...}}classChild{weak_ptr_parent;~Child{_parent.lock()->getSystem()->blah();}}Child析构函数总是崩溃,因为当~Child()运行时_parent总是过期。是否有针对这种怪现象的典型解决方案?简而言之,有没有办法在~Chil

C++ STL:将派生虚拟类用作 std::sort() 的 "Strict Weak Ordering"

我使用std::sort()撞墙了。我有一个纯虚类(名为Compare),方法的调用者派生自该类(名为MyComp)。我将纯虚拟类用于我的API原型(prototype):voidObject::DoSort(Compare&comp){std::sort(this->mKeys.begin(),this->mKeys.end(),comp);}来电者:classMyComp:publicCompare{booloperator()(constRow*r1,constRow*r2){...}}cmp;...obj->DoSort(cmp);Linux上的g++编译器提示:“无法分配类型