virtual

Access violation after catching dll exception

删除回忆录丶 提交于 2019-12-06 03:06:30
I have to load modules as dlls dynamically at runtime as they are not known ahead of time, just that they conform to a class interface. What I noticed is that after I catch an exception thrown by the dll (in the main program in the main thread), the right destructors are called and the modules destroyed and dll's unloaded, but then as the } at the end of the catch block is reached by the Visual Studio C++ debugger when stepping line by line, I get another exception which crashes the program with First-chance exception at 0x68ad2377 (msvcr90d.dll) in xxxxx.exe: 0xC0000005: Access violation

vftable - what is this?

a 夏天 提交于 2019-12-06 02:26:26
问题 What is vftable in high programming languages? I read something like it's the address of a virtual object structure, but this is a pretty messy information Can someone please explain it? 回答1: It most likely stands for "Virtual Function Table", and is a mechanism used by some runtime implementations in order to allow virtual function dispatch. Mainstream C++ implementations (GCC, Clang, MSVS) call it the vtable . C has no polymorphism. I could only speculate about other languages. Here's what

How to override a virtual function with a non-virtual function?

那年仲夏 提交于 2019-12-06 02:17:25
Refer to this question: Hide virtual function with non-virtual override And this question: override on non-virtual functions A function that overrides a virtual function is virtual too, even though it's not explicitly declared virtual. My technical question is: Is there away to make that overriding function non-virtual (and applies that to classes lower in the hierarchy)? In other words, can I turn the "virtuality" off? Obviously we can override a non-virtual function with a virtual function. Can we do the opposite, i.e. to override a virtual function with a non-virtual function? You are

virtual constructor idiom with smart pointers

会有一股神秘感。 提交于 2019-12-06 01:35:25
问题 I've a hierarchy of polymorphic classes, say a Shape abstract base class together with its derived classes, e.g. Rectangle , Circle , etc. Following the Virtual Constructor Idiom, I was wondering why we need that the return types of the virtual constructor functions in the derived classes should return the same type as in its parent class when using smart pointers? For example, see the code below, where the clone() and create() member functions need to return smart_pointers to the Shape class

Simulate or Virtual Twain source for Twain development [closed]

对着背影说爱祢 提交于 2019-12-06 00:46:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . For developing a web based scan solution, I would love to test it on Windows or Mac without actually hooking up a scanner to my box. So is there a program/tool that emulates or gives me a virtual twain source with some default image data? 回答1: The Twain sample driver that comes along with the twain sample

Virtual inheritance in C++

坚强是说给别人听的谎言 提交于 2019-12-06 00:28:12
I was reading the Wikipedia article on virtual inheritance. I followed the whole article but I could not really follow the last paragraph This is implemented by providing Mammal and WingedAnimal with a vtable pointer (or "vpointer") since, e.g., the memory offset between the beginning of a Mammal and of its Animal part is unknown until runtime. Thus Bat becomes (vpointer,Mammal,vpointer,WingedAnimal,Bat,Animal). There are two vtable pointers, one per inheritance hierarchy that virtually inherits Animal. In this example, one for Mammal and one for WingedAnimal. The object size has therefore

Virtual function calling a non-virtual function

那年仲夏 提交于 2019-12-06 00:18:54
I wrote the following piece of code to test my understanding of virtual inheritance. Apparently, I still don't get it fully. Here is my code (followed by my question): #include <iostream> #include <vector> using namespace std; class Foo { public: virtual void foo(); void foo2(); }; void Foo::foo() { cout << "In FOO - foo 1" << endl; foo2(); } void Foo::foo2() { cout << "In FOO - foo 2" << endl; } class Bar : public Foo { public: void foo(); void foo2(); }; void Bar::foo() { cout << "In BAR - foo 1" << endl; foo2(); } void Bar::foo2() { cout << "In BAR - foo 2" << endl; } int main() { Foo* f =

Virtual functions table offset

强颜欢笑 提交于 2019-12-05 23:29:36
I would like to ask you on what does the offset of the table of virtual functions for a class depend? I mean, from what I've read it at least depends on compiler, but does it varies from class to class? Edit: by offset I mean the position of the table relative to the address of the owner object. Edit: example code: void **vtable = *((void***)(((char*)object)+offset)); int **ivtable=(int **)vtable; void* firstFunction = (void*) ivtable[0]; There is certainly a dependency on the exact class. Remember that C++ has multiple inheritance (MI). The consequence of MI is that a single object may have

Covariant virtual functions return type problem

空扰寡人 提交于 2019-12-05 22:20:34
I have following code: #include <iostream> using namespace std; class Child1 { int i; }; class Child2 : public Child1 { int j; }; class Base1 { public: virtual Child1& getChildren() { cout << "Children1" << endl; return children; } private: Child1 children; }; class Base2 : public Base1 { public: virtual Child2& getChildren() { cout << "Children2" << endl; return children; } private: Child2 children; }; This code compiles fine but when I change the return type of getChildren() from reference type to object type in either or both Base1 and Base2 (e.g. virtual Child2 getChildren() , I get the

Speed of virtual call in C# vs C++

梦想的初衷 提交于 2019-12-05 22:06:35
问题 I seem to recall reading somewhere that the cost of a virtual call in C# is not as high, relatively speaking, as in C++. Is this true? If so - why? 回答1: A C# virtual call has to check for “this” being null and a C++ virtual call does not. So I can’t see in generally why a C# virtual calls would be faster. In special cases the C# compiler (or JIT compiler) may be able to inline the virtual call better then a C++ compiler, as a C# compiler has access to better type information. The call method