virtual

Inheritance of virtual member functions with the same name

∥☆過路亽.° 提交于 2019-12-22 17:42:18
问题 class A { A() {}; virtual ~A() {}; virtual void Start() {}; virtual void Start(float a) {}; }; class B : public A { }; class C : public A { virtual void Start(float a) {}; } ... B BObj; BObj.Start(); // -> fine, no complain from g++ ... ... C CObj; CObj.Start(); // -> not fine -> error: no matching function for call to ‘C::Start()’ ... I suspect that the problem comes from that both virtual functions have the same name, but different parameter signature. What I would like to know is that this

Can the implementation of a virtual function be put in the header file

给你一囗甜甜゛ 提交于 2019-12-22 12:42:21
问题 usually if we put an implementation of a non-virtual member function in the header file that function would be inlined. how about if we put the implementation of a virtual member function in the header file? I guess it would be the same as putting it in the cpp file because inlining and polymorphism do not work together. Am I right on this? 回答1: Putting the implementation of a method in the header file doesn't make it inline. Putting it in the class declaration does. I'll assume that's what

Virtual function default parameters and overloading

送分小仙女□ 提交于 2019-12-22 10:09:08
问题 This question refers to common problems discussed in these questions: Can virtual functions have default parameters? Virtual functions default parameters Here is what currently happens in c++ with default parameters to virtual functions: struct Base { virtual void foo(int one = 1, int two = 2) { cout << "one: " << one << " two: " << two << endl; } }; struct Derived : public Base { virtual void foo(int one = 3, int two = 4) { Base::foo(one, two); cout << " derived!" << endl; } }; int main() {

Virtual inheritance in C++

淺唱寂寞╮ 提交于 2019-12-22 10:04:21
问题 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

Access violation after catching dll exception

蹲街弑〆低调 提交于 2019-12-22 09:48:55
问题 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

Virtual Function During Construction Workaround

喜欢而已 提交于 2019-12-22 09:25:07
问题 I've got a base class that has a virtual function. I want to call that class during the construction because I want the function called for each of the derived classes. I know I can't call a virtual function during construction, but I can't think of an elegant (i.e., avoid repeating code) solution. What are some work arounds to calling a virtual function during construction? The reason I want to avoid this is because I don't want to have to create constructors that just call the base class.

How to create a virtual audio device

十年热恋 提交于 2019-12-22 08:44:52
问题 I am working on a project in C# for which I need to create several virtual audio devices. Later I will be doing some switching with them on my own. Does maybe anyone know a nice library that would allow me to do it problematically on my own. To create instances of audio devices. (commercial is OK, but free .dll would be better) Another solution, that would be an optional solution, is to find a software that creates virtual audio devices according to my desires. 回答1: Unfortunately, you won't

A virtual display for ubuntu server

社会主义新天地 提交于 2019-12-22 08:02:00
问题 My question is: is there a way to set up a virtual display as default display on a linux server (so that all GUI application launched will be displayed on that display, if no counter indication is made)? I tried using this: xvfb-run java -jar autoclick.jar , which produces the following output : searching graphic devices is Headless:false screen N°1 width:1600 height:900 just 1 robot click: Magic button clicked ! and here's the autoclick code : System.out.println("searching graphic devices");

How to call virtual function of derived class through base class pointer

早过忘川 提交于 2019-12-22 05:59:27
问题 Let's see this code: class CBase { public: virtual vfunc() { cout << "CBase::vfunc()" << endl; } }; class CChild: public CBase { public: vfunc() { cout << "CChild::vfunc()" << endl; } }; int main() { CBase *pBase = new CBase; ((CChild*)pBase)->vfunc(); // !!! important delete pBase; return 0; } The output is: CBase::vfunc() But I want to see: CChild::vfunc() Explicit ((CChild*)pBase) casts to type "CChild*". So why to call derived vfunc() I need replace "important" string with: ((CChild*

What is the reason of implicit virtual-ness propagation?

余生颓废 提交于 2019-12-22 05:29:25
问题 I've only been working with C++ for 2~3 months and recently I found out about the identifier, final , that comes after a virtual function. To this day, I believed that omission of virtual will stop the propagation of virtualness but I was wrong. It implicitly propagates. My question is this. Why allow implicit propagation? Why can't an existence of virtual make a function virtual and absense of virtual make a function not virtual? Is is better in some circumstance? or Was it, back in the day