vtable

Why can't virtual functions use return type deduction?

主宰稳场 提交于 2019-11-30 21:33:36
问题 n3797 says: § 7.1.6.4/14: A function declared with a return type that uses a placeholder type shall not be virtual (10.3). Therefore the following program is ill-formed: struct s { virtual auto foo() { } }; All I can find for the rationale is this vague one-liner from n3638: virtual It would be possible to allow return type deduction for virtual functions, but that would complicate both override checking and vtable layout, so it seems preferable to prohibit this. Can anyone provide further

Alternatives to vtable

巧了我就是萌 提交于 2019-11-30 20:17:08
Vtables are ubiquitous in most OO implementations, but do they have alternatives? The wiki page for vtables has a short blurb, but not really to much info (and stubbed links). Do you know of some language implementation which does not use vtables? Are there are free online pages which discuss the alternatives? Yes, there are many alternatives! Vtables are only possible when two conditions hold. All method calls can be determined statically. If you can call functions by string name, or if you have no type information about what objects you are calling methods on, you can't use vtables because

Loading an EXE as a DLL, local vftable

跟風遠走 提交于 2019-11-30 14:19:43
I have an exe named test.exe which is usually used as a stand-alone application. I want to use this exe as a module (a dll) inside another application, app.exe. The code in test.exe does something really simple like: void doTest() { MyClass *inst = new MyClass(); inst->someMethod(); } Where someMethod() is virtual and MyClass has a virtual d'tor. doTest() is exported from test.exe and thus a lib called test.lib is created app.exe is linked with this lib to statically load test.exe when it starts. When I'm running test.exe stand-alone it runs just fine but when I'm running it loaded from within

COM method offsets in Delphi

强颜欢笑 提交于 2019-11-30 13:09:58
In Delphi, how do I find out the the address of a COM method? I can hardcode the offsets //0 is the offset of the QueryInterface method p := TPonterArray(pointer(SomeInterface)^)[0]; but I would prefer to use symbolic names. The folllowing obviously does not work: var M : TMethod; ... M := TMethod(SomeInterface.QueryInterface); Thanks! You can use the vmtoffset assembler directive to get the byte offset of an interface method relative to the start of the interface's method table. Take a look at the implementation of _IntfCast in System.pas , for example: call dword ptr [eax] + vmtoffset

How is the deletion of a pointer detected using dynamic cast

て烟熏妆下的殇ゞ 提交于 2019-11-30 09:37:31
As shown here , one can use dynamic_cast to detect a deleted pointer: #include <iostream> using namespace std; class A { public: A() {} virtual ~A() {} }; class B : public A { public: B() {} }; int main() { B* pB = new B; cout << "dynamic_cast<B*>( pB) "; cout << ( dynamic_cast<B*>(pB) ? "worked" : "failed") << endl; cout << "dynamic_cast<B*>( (A*)pB) "; cout << ( dynamic_cast<B*>( (A*)pB) ? "worked" : "failed") << endl; delete pB; cout << "dynamic_cast<B*>( pB) "; cout << ( dynamic_cast<B*>(pB) ? "worked" : "failed") << endl; cout << "dynamic_cast<B*>( (A*)pB) "; cout << ( dynamic_cast<B*>(

C++: Class specialization a valid transformation for a conforming compiler?

独自空忆成欢 提交于 2019-11-30 06:47:00
Hopefully this isn't too specialized of a question for StackOverflow: if it is and could be migrated elsewhere let me know... Many moons ago, I wrote a undergraduate thesis proposing various devirtualization techniques for C++ and related languages, generally based on the idea of precompiled specialization of code paths (somewhat like templates) but with checks to choose the correct specializations are chosen at runtime in cases where they cannot be selected at compile-time (as templates must be). The (very) basic idea is something like the following...suppose you have a class C like the

How are vtables implemented in c++ and c#?

Deadly 提交于 2019-11-30 05:27:43
Lets have this situation (in c++, in c# classes A,B are interfaces): class A { virtual void func() = 0; }; class B { virtual void func() = 0; }; class X: public A, public B { virtual void func(){ var = 1; } int var;}; X * x = new X; // from what I know, x have 2 vtables, is this the same in c#? A * a = (A*)x; // a == x B * b = (B*)x; // here b != x, so when calling b->func(), how is the address of var correct? Does the c# compiler create always one vtable? Does it make any pointer fixups when casting? Not to be overly pedantic, but the C# compiler does not get involved at this level. The

Why vptr is not static?

时光毁灭记忆、已成空白 提交于 2019-11-30 05:02:21
Every class which contains one or more virtual function has a Vtable associated with it. A void pointer called vptr points to that vtable. Every object of that class contains that vptr which points to the same Vtable. Then why isn't vptr static ? Instead of associating the vptr with the object, why not associate it with the class ? The runtime class of the object is a property of the object itself. In effect, vptr represents the runtime class, and therefore can't be static . What it points to, however, can be shared by all instances of the same runtime class. Your diagram is wrong. There is

What is the structure of virtual tables in C++?

两盒软妹~` 提交于 2019-11-30 04:24:22
For Example I have two "intefaces" and class type: class IPlugin { public: virtual void Load(void) = 0; virtual void Free(void) = 0; }; class IFoo { public: virtual void Foo(void) = 0; }; class Tester: public IPlugin, public IFoo { public: Tester() {}; ~Tester() {}; virtual void Load() { // Some code here } virtual void Free() { // Some code here } virtual void Foo(void) { // Some code here } }; What structure vtab actually has for instance of type Tester ? And how would be dynamic_cast operator act ( I mean how dynamic_cast operator would scan vtab for valid reference type convertion) in

Alternatives to vtable

戏子无情 提交于 2019-11-30 03:51:47
问题 Vtables are ubiquitous in most OO implementations, but do they have alternatives? The wiki page for vtables has a short blurb, but not really to much info (and stubbed links). Do you know of some language implementation which does not use vtables? Are there are free online pages which discuss the alternatives? 回答1: Yes, there are many alternatives! Vtables are only possible when two conditions hold. All method calls can be determined statically. If you can call functions by string name, or if