草庐IT

weak-template-vtables

全部标签

c++ - 编程语言理念 : Avoiding vtable lookups

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭9年前。一段时间以来,我一直在考虑一种编程语言的想法:它在语法上基本上是C++和Java类的,用于系统编程(或者实际上任何需要高性能的编程),但是,在我看来,这是一种比C++更有趣的语法。我在考虑如何处理分层类结构中的虚拟方法(我的语言不包括多重继承),以及避免vtable查找的方法。我的问题是双重的:据我了解,vtable查找如此影响性能的原因(至少在游戏开发等时间紧迫的场景中)是因为它需要引用对象vt

c++ - map 中过期的 weak_ptr 会发生什么

我想了解weak_ptr已过期的映射中的条目(类型为boost::weak_ptr)会发生什么。map中的相应条目是否会自动删除?键是一个整数,对应的值是一个weak_ptr。我写的示例代码,但无法编译#include#include#includeusingnamespacestd;classFoo:publicboost::enable_shared_from_this{public:Foo(intn=0):bar(n){std::coutinc_ref(){returnshared_from_this();}private:intbar;};std::map>mappy;intm

c++ - 完全纯虚拟类的 Vtable 放置

根据我对C++规范的(有限)了解,具有虚拟成员的类的vtable放在第一个非纯非内联虚拟方法的定义处。编译器如何处理从具有所有纯虚拟方法(例如接口(interface))的类继承的类?这种情况下vtable放在哪里? 最佳答案 vtable存储已实现的虚拟方法的地址。如果一个类的所有方法都是纯虚的并且没有实现,则不需要生成vtable。如果没有从它派生的一些类并实现这些方法,您将无法使用这样的类。每个实现了虚方法的类都有自己的单个虚表,其中包含所有虚方法的地址:它不以任何方式引用基类的虚表;地址重复。所以如果你有一个继承自另一个类的

c++ - g++ 可变参数模板。简单示例代码无法编译,提示 'Not a template'

我正在探索这个陌生的领域,并想尝试来自DannyKalev'stutorialonthematter的一个简单示例.代码非常简单:templatestructCount{staticconstintvalue=0;};templatestructCount//partialspecialization{staticconstintvalue=1+Count::value;};但是gcc4.4.7甚至4.7.0提示(尽管-std=c++0x-std=gnu++0x标志):/src/tests/VTemplates.h:12:8:error:'Count'isnotatemplate/sr

c++ - 错误 C2899 : typename cannot be used outside a template declaration

我正在MSV2010中尝试以下内容namespacestatismo{templatestructRepresenterTraits,3u>>{typedefitk::Image,3u>VectorImageType;typedefVectorImageType::PointerDatasetPointerType;typedefVectorImageType::PointerDatasetConstPointerType;typedeftypenameVectorImageType::PointTypePointType;typedeftypenameVectorImageType:

c++ weak_ptr在取消引用后过期?

我是智能指针的新手,我正在思考为什么weak_ptr在取消引用运算符后会过期。我用来测试的代码在这里:#include#include#includeusingnamespacestd;structnode{weak_ptrparent;shared_ptrchild;intval;};shared_ptrfoo(){shared_ptra=make_shared();shared_ptrb=make_shared();a->val=30;b->val=20;b->parent=a;a->child=b;returna;}intmain(){shared_ptrc=foo();node

C++ : friend declaration ‘declares a non-template function

我在重载时遇到问题流运算符(operator),我找不到解决方案:templateclassNVector{inlinefriendstd::ostream&operator&rhs);};templateinlinestd::ostream&NVector::operator&rhs){/*SOMETHING*/returnlhs;};它产生以下错误信息:warning:frienddeclaration‘std::ostream&operatorerror:‘std::ostream&NVector::operator如何解决这个问题?非常感谢。 最佳答

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]

C++ 如何使 template<T>f() 为整数 T 返回 -1,为指针类型返回 nullptr

我需要完成以下任务:templatef(){:return{-1ifTisofintegraltype,elsenullptr}}在我的特定用例中,T可以是四种类型之一:intPy_ssize_t//ssize_tPy_hash_t//ssize_tPyObject*//PyObjectissomeCstruct这是我迄今为止最好的解决方案:templateTtest(typenameenable_if::value,void*>::type=nullptr){return-1;}templateTtest(typenameenable_if::value,void*>::type=n

c++ - 尝试理解 std::enable_shared_from_this<T> 但使用它会导致 bad_weak_ptr

我试图理解std::enable_shared_from_this类的行为,但我无法理解。所以我写了一个简单的程序来测试不同的情况。问题谁能解释一下下面代码的行为,因为我无法解释观察到的结果。谢谢你的帮助。代码#include#includestructC:std::enable_shared_from_this{};intmain(){{//test1std::shared_ptrfoo,bar;foo=std::make_shared();bar=foo->shared_from_this();//okstd::coutfoo=std::shared_ptr(newC);std::