草庐IT

weak-template-vtables

全部标签

c++ - 无论如何要从他们的 vtable 重建一些保存的类?

我正在将一些对象复制到一个文件中,它们都派生自同一个类。但我希望能够在加载它们之后调用它们的函数来执行该类应该执行的操作,这是我到现在为止所做的:#include#includeusingnamespacestd;structa{virtualvoidprint(){coutprint();testifile.read((char*)x,sizeof(b));x->print();}我的示例工作正常,但如果我注释保存部分然后运行程序,则vtable似乎对新运行的应用程序无效(尽管我的代码中没有任何更改)。问题是我的文件管理器类不知道所有可能从我的基础对象派生的对象,我想重建我所有的应用

c++ - C++ vtables中的双重间接

我编写了这个非常简单的C++程序,我想知道为什么编译器将vtable布局为跨越两个指针取消引用。这是C++程序:classFoo{public:virtualvoidbar(){}};intmain(intargc,char*arv[]){Foofoo;Foo*foo_p(&foo);foo_p->bar();}现在,我可以查看编译器生成的程序集:$g++-ggdb-Wall-O0-Stest.cpp以下是相关部分:.loc190leaq-16(%rbp),%rax#puttheaddressof'foo'in%raxmovq%rax,%rdi#useitasthefirstargum

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++ - 使用 C++ 的 OpenGL : vtable troubles when passing class array to glTexImage2d

我用floatr、floatg、floatb、floatalpha创建了一个类Color。它有一个带有虚拟析构函数的基类。我正在尝试将Color数组传递给opengl函数glTexImage2D,其中GL_RGBA组织类型为float(这将是一个数组{floatr,floatg,floatb,floatalpha}).这要求Color仅包含4个float(16字节大小)。但是,sizeof(Color)显示我的类有一个20字节的大小,因为Color的基类有一个vtable,感谢析构函数。如何保留我的vtable并将我的Color数组传递给glTexImage2D?

c++ - C++ ABI 是否指定 vTable 和 RTTI 信息应该如何存在?

像GCC/VC这样的流行实现使用多态对象的第一个size_t空间作为指针,指向一个vtable结构。这是最新的C++ABI的一部分吗?RTTI的实现如何,C++ABI有没有规定如何实现?谢谢 最佳答案 不,C++标准没有指定这些应该如何实现。没有单一的C++ABI。 关于c++-C++ABI是否指定vTable和RTTI信息应该如何存在?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questio

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

templates - 使用多个模板的运算符重载

templateclassA{private:Tm_var;public:operatorT()const{returnm_var;}........}templateconstAoperator+(constU&r_var1,constV&r_var2){returnA((T)r_var1+(T)r_var2);}想法是为以下情况重载+运算符一次(而不是三次):number+A,A+number,A+A(其中number是类型T,与m_var相同)。一个有趣的情况是,如果m_var是例如int和r_var是long。任何帮助将不胜感激。谢谢。 最佳答案

c++ - 转发声明 : templates and inheritance

在编写框架时遇到以下问题:我有classA和classB派生自classA。classA有一个返回B*的函数。当然,这并不难:#includeusingnamespacestd;classB;//forwarddeclarationclassA{public:B*ReturnSomeData();};classB:publicA{};//Implementation:B*A::ReturnSomeData(){returnnewB;//doesn'tmatterhowthefunctionmakespointer}intmain(){Asth;cout但是我不得不使用像这里这样的模板:

c++ - weak_ptr 奇怪的复制构造函数

以下是weak_ptr的2个构造函数:http://msdn.microsoft.com/en-us/library/bb982126.aspxweak_ptr(constweak_ptr&);templateweak_ptr(constweak_ptr&);实际代码(来自内存):weak_ptr(constweak_ptr&_Other){//constructweak_ptrobjectforresourcepointedtoby_Otherthis->_Resetw(_Other);}templateweak_ptr(constweak_ptr&_Other,typenameen

c++ - weak_ptr C++ 中的比较运算符

我在新的STL成员中还是个新手。谁能指出为什么这段代码会出现段错误?#include#include#include#include#includeusingnamespacestd;structStubClass{weak_ptrb;intc;friendbooloperator==(StubClassx,StubClassy);friendbooloperatorx):b(x){c=5;}};booloperator==(StubClassd,StubClassc){returnd.b==c.b;}booloperatorspPtr(newstring("Hello"));weak