草庐IT

weak-template-vtables

全部标签

c++ - 反汇编多重继承中的虚拟方法。 vtable 是如何工作的?

假设以下C++源文件:#includeclassBaseTest{public:inta;BaseTest():a(2){}virtualintgB(){returna;};};classSubTest:publicBaseTest{public:intb;SubTest():b(4){}};classTriTest:publicBaseTest{public:intc;TriTest():c(42){}};classEvilTest:publicSubTest,publicTriTest{public:virtualintgB(){returnb;}};intmain(){EvilT

c++ - 错误 : ‘template<class> class std::auto_ptr’ is deprecated

我正在使用scons和ubuntu。当我使用'scons'制作一些程序时,会发生错误,例如,src/db/DBTextLoader.cc:296:3:error:‘templateclassstd::auto_ptr’isdeprecated[-Werror=deprecated-declarations]/usr/include/c++/5/bits/unique_ptr.h:49:28:note:declaredheretemplateclassauto_ptr;这是我的命令;$./configuer$sourcesomething.sh$scons其实我也不知道。我已经在搜索这个

c++ - Soft (not : weak) references in C++ - Is it possible? 有实现吗?

在C++中,我使用boost::shared_ptr和boost::weak_ptr自动删除不再需要的对象。我知道这些与引用计数一起工作。在Java中,内存由垃圾收集器管理,垃圾收集器将内置对象引用视为strong,将WeakReference视为weak并且SoftReference作为介于两者之间的东西(可能被GC收集,但也可能在GC中幸存下来),这对于缓存对象一段时间非常方便,但一旦可用内存变低就将它们丢弃。所以现在我又回到了C++中,我想念软引用带来的舒适感。我想知道软引用是否完全适用于引用计数。当对象的最后一个strong引用被清除,并且还剩下一个soft引用时,到底什么时候

c++ - 错误 : Expected template-name before '<' token

我正在尝试编译一个实现chain和chainNodes的程序并在以下行(第22行)出现错误:classchain:publiclinearList错误是:Error:expectedtemplate-namebefore'知道为什么会出现这种情况吗?我的代码如下://linkedimplementationofalinearlist//derivesfromabstractclasslinearListjusttomakesure//allmethodsoftheADTareimplemented#ifndefchain_#definechain_#include#include#in

C++11 : Is it possible to give fixed-template-parameted template to varidic-template-template-parameter?

(是的,由于我糟糕的英语,标题很奇怪;我希望有人能改进它。)接听thisquestion,我发现这段代码有效:templateclassA{};templateclassU>classB{};intmain(){Bit_works;}..虽然templateclass和templateclass不相等。我试图弄清楚为什么这是可能的,并观察了N3337standard的[temp.param],但我找不到任何东西。怎么可能? 最佳答案 是的,这是可能的。C++1114.3.3/3特别允许,并提供了一个例子。3Atemplate-arg

c++ - 从 weak_ptr 泄漏原始指针的可移植 hack

我有一个由shared_ptr组成的对象结构,加上weak_ptr以避免循环。原始指针是不行的,因为boost::serialization在通过对象跟踪作为序列化时间进行反序列化时需要恢复共享指针和弱指针。对象生命周期模式很复杂(粒子模拟)但完全可以预测。每当我使用weak_ptr::lock()时,我确信指针仍然有效。通常,我使用lock().get(),因为我只需要在很短的时间内使用该对象。现在,lock().get()对性能有影响,因为它会增加共享计数(在lock()中),然后在不久之后减少它(临时shared_ptr被破坏)。这boost.develpost从2002年开始,

c++ - std::weak_ptr:锁或 shared_ptr 构造函数?

似乎有两种方法可以暂时获取weak_ptr指向的资源的所有权:使用lock()将weak_ptr传递给shared_ptr构造函数这两者都会产生一个shared_ptr,如果weak_ptr为空并且锁返回一个nullptrshared_ptr构造函数抛出异常。所以问题是:什么时候应该使用一个或另一个?是否有与此相关的一般准则或最佳做法? 最佳答案 复制自http://en.cppreference.com/w/cpp/memory/weak_ptr/lockBoththisfunctionandtheconstructorofstd

c++ - 为什么头文件中定义的 C++ 虚函数可能无法在 vtable 中编译和链接?

情况如下。我有共享库,其中包含类定义-QueueClass:IClassInterface{virtualvoidLOL(){dosomemagic}}我的共享库初始化类成员QueueClass*globalMember=newQueueClass();我的共享库导出C函数,它返回指向globalMember的指针-void*getGlobalMember(void){returnglobalMember;}我的应用程序像这样使用globalMember((IClassInterface*)getGlobalMember())->LOL();现在非常棒的东西-如果我不从共享库引用LOL

c++ - 奇怪的 "Could not deduce template argument for ' T'"错误

错误在this代码://myutil.htemplateTConditionalInput(LPSTRinputMessage,LPSTRerrorMessage,predicatecondition);//myutil.cpptemplateTConditionalInput(LPSTRinputMessage,LPSTRerrorMessage,Predcondition){Tinputcout>input;while(!condition(input)){cout>input;}returninput;}...//c_main.cppintrow;row=ConditionalI

c++ - Template类拷贝构造函数的写法

如何为模板类编写复制构造函数。因此,如果模板参数是另一个用户定义的类,它的复制构造函数也会被调用。下面是我的课templateclassVertex{public:Vertex(_TyVin):m_Label(in){}~Vertex(){}booloperator 最佳答案 要么a)根本不是,只依赖于编译器提供的默认值;或b)仅调用成员的复制构造函数:templatestructFoo{Tvar;Foo(constFoo&rhs):var(rhs.var){}};重点当然是编译器提供的默认拷贝构造函数做了完全一样的事情:它一个一个