virtual

C++ collection of abstract base classes

一笑奈何 提交于 2019-12-12 01:32:02
问题 how can I create STL collection of classes which implement abstract base class using the base class as collection value, without using pointers? is there something in Boost that allows me to implement it? The collection specifically is map. Thanks 回答1: You cannot avoid pointers completely. You must store pointers in the collection if you want to avoid Object slicing. Boost has a container that hides the pointers pretty well: ptr_map 回答2: The Boost Pointer Container Library does what you want.

How to hide virtual method in C++ and keep interface?

懵懂的女人 提交于 2019-12-11 17:33:41
问题 I want make a SharedInterrupt class(B) which will serve in series many objects in one interrupt vector. But the derived classes(C..) of SharedInterrupt class(B) must have same ISR() function(func) as SingleInterrupt class(A). Is it possible? class A { public: virtual void func() = 0; }; class B : public A { private: void func() // I want to hide this method from derived classes (C, etc.) { // some code } public: virtual void func() = 0; // And I want to keep A's interface, but compiler error!

Create virtualedit block around selection

♀尐吖头ヾ 提交于 2019-12-11 16:24:02
问题 I'm trying to create a script what permits me to select a few lines and create a virtualedit block around it; 1 column after the longest line. This is my code function! VirtualEdit() let EndLine = line("'>") set virtualedit = all let maxlength = max(map(range(line("'<"), line("'>")), "virtcol([v:val, '$'])"))-1 call cursor(1,maxlength+1) normal "^Q".EndLine."jc<space><ESC>" set virtualedit = '' endfunction What it must do is 1) Control the longest line in my selection (maxlength). 2) Put the

Simulate Mouse/Keyboard Input In WPF

会有一股神秘感。 提交于 2019-12-11 15:03:22
问题 There are many questions relating to simulating mouse/keyboard input in WPF (and Windows, for that matter). I have something a little different than the usual question, I think, and I'd like your input. Most posts I've seen have a specific higher level action in mind: I want to click this, I want to move the mouse here, etc. To emulate these, one can simply use routed events. However, I'm hoping to operate a mouse from a remote app and would like to input mouse events at a low-level: current

Missing Virtual Destructor Memory Effects

拟墨画扇 提交于 2019-12-11 13:40:22
问题 According to the standard, polymorphism with a missing virtual destructor leads to undefined behavior. In practice, it really leads to the destructor for the derived class not being called when the parent class is deleted. However, does it also lead to memory leaks in any common compilers/systems? I'm particularly interested in g++ on Android/Linux. Specifically, I'm referring to whether the deletion of memory for the derived class will somehow leak. Consider: class Base {} class Derived {

Template and Virtual functions in C++ ? allowed ?

为君一笑 提交于 2019-12-11 09:51:48
问题 I've read over the web that template virtual functions are not allowed , is it true ? It's a little bit weird since this code compile great on my Eclipse's g++ template <class T> class A { public: virtual ~A<T>() { } virtual void printMe() {cout << "I am A class" << endl;} }; template <class T> class B: public A<T> { public: void printMe() {cout << "I am B class" << endl;} }; int main() { A<int> * ptr = new B<int>; ptr->printMe(); delete ptr; return 0; } Regards,Ronen 回答1: virtual methods in

C++ Derived class is abstract error

天大地大妈咪最大 提交于 2019-12-11 09:11:11
问题 I am having a trouble where Dialin, the derived class is abstract. I'm not sure why since the only virtual function I have has the same parameters and same return types. From what I've read, that's the only restriction, but apparently I'm wrong. Here's my code: Header: class Event{ class ModemSimV2; public: Event( ); Event( const Event &e ); ~Event( ); virtual void process( ModemSimV2 &m ) = 0; protected: int who; // the number of the user int time; // when the event will occur int what; //

How to set up Apache virtual host such as http://home/, http://office/, etc

别等时光非礼了梦想. 提交于 2019-12-11 08:24:31
问题 So rather than http://localhost, is it possible to set up multiple virtual hosts on the same local computer so I can access: http://home/ http://office/ http://docs/ for different websites that are hosted at different document root directories in my computer? 回答1: Install multiple virtual hosts Check this page for a useful information on what you want to know. 来源: https://stackoverflow.com/questions/5385969/how-to-set-up-apache-virtual-host-such-as-http-home-http-office-etc

C++: g++ compiler: clash of stdio with virtual functions?

百般思念 提交于 2019-12-11 08:21:30
问题 I am not able to use stdio combined with virtual functions (Windows Vista, Cygwin, GCC 4.8.2) #include <stdio.h> class A { public: // If I make g() as virtual, stdio doesn't print. virtual void g() {} }; int main() { A a; // Or I could remove this object to make stdio print. printf("testing\n"); } With hint by "Borgleader", I found that it works when used with "-O2" option. Linking seems to be different when used with/without "-O2". /home/user> g++ test.cc /home/user> ./a.exe /home/user> ldd

Virtual Method not calling dervied class method. - C++

久未见 提交于 2019-12-11 07:32:01
问题 I have a method in both the base class and the derived class. When I call this method on an object in the derived class it calls the base class method and not the derived class method. Here is my code: Person.h class Person { ... public: ... virtual void coutPerson(); }; Person.cpp void Person::coutPerson() { cout << name << endl; birthday.coutDate(); phoneNumber.coutPhoneNumber(); cout << city << ", " << state << endl; } Student.h class Student : public Person { ... public: ... virtual void