virtual

How to prevent derived class from making a private/protected virtual function public?

时间秒杀一切 提交于 2019-11-28 08:01:07
问题 There are good reasons for constructing the base class interface with all virtual functions as private or protected (see this). But then how does one prevent the derived classes (which may be in the hands of external clients) from making the private virtual function as public? In Virtually Yours, the authors talk about this problem, but no solution is discussed. Edit : From your answers and as I previously thought, it seems there is no way to prevent this. But since in this situation, it is

DataGridView virtual mode with a simple list as a source

我只是一个虾纸丫 提交于 2019-11-28 07:34:00
问题 Previously I asked a question about my dataGridView's performance due to it havign to display a large amount of rows that get added based on an incoming stream. Multiple solutions were given, one of them enabling virtual mode. MSDN has an article on the subject but it feels more complicated than what I need as it uses a database and an editable field. My DataGridView is only for displaying and the data I display is placed in a List. After I accepted an answer I received this link: http://www

Number of Virtual tables and Virtual Pointers in a C++ Program

删除回忆录丶 提交于 2019-11-28 07:02:41
Let say we have below program: class A { public: virtual fun(){}; }; class B:public A { public: virtual fun(){}; }; int main() { A a1; B b1; } My question is how many vtables and how many vptrs will be created, when we run this program? Its heavily implementation dependent, but generally you'll get one vtable object per class that has any virtual functions (classes with no virtual functions or bases don't need them), and one vptr per object of a class with a vtable (pointing at the class's vtable). Things get more complex if you have multiple inheritance and virtual base classes -- which can

In an abstract class constructor, why I do need to call a constructor of a virtual base that will never to called?

旧街凉风 提交于 2019-11-28 06:54:25
问题 I face the well known "dreaded" diamond situation : A / \ B1 B2 \ / C | D The class A has, say the constructor A::A(int i) . I also want to forbid a default instantiation of a A so I declare the default constructor of A as private . The classes B1 and B2 are virtually derived from A and have some constructors and a protected default constructor. [edit] The constructors of B1 and B2 don't call the default constructor of A . [reedit] The default constructors of B1 and B2 don't call the default

need a virtual template member workaround

假如想象 提交于 2019-11-28 06:54:05
I need to write a program implementing the visitor design pattern. The problem is that the base visitor class is a template class. This means that BaseVisited::accept() takes a template class as a parameter and since it uses 'this' and i need 'this' to point to the correct runtime instance of the object, it also needs to be virtual. I'd like to know if there's any way around this problem. template <typename T> class BaseVisitor { public: BaseVisitor(); T visit(BaseVisited *visited); virtual ~BaseVisitor(); } class BaseVisited { BaseVisited(); template <typename T> virtual void accept

open the Windows virtual keyboard in a Java program

有些话、适合烂在心里 提交于 2019-11-28 06:50:58
问题 I would like to create an event in a button. When I click in the button, I would like to open the Windows virtual keyboard. Can you help me with the code? Thank you for your collaboration. Best regards. 回答1: I think it would be as simple as this: Runtime.getRuntime().exec("osk"); 回答2: You can use getRuntime to execute it: import java.io.IOException; public class ShowVirtualKeyboard{ public static void main(String argv[]) throws IOException { String sysroot = System.getenv("SystemRoot");

How to disable virtual home button in any activity?

爱⌒轻易说出口 提交于 2019-11-28 06:47:53
问题 I need to disable 3 virtual buttons in any activity in my app. I disabled back button and multitask button somehow but I cannot dsable home button. I tried onAttachedToWindow() style answers on stackoverflow but they didn't work for me. I don't want to disable home button for entire app, I just want to disable it for a single activity window. Thanks for your helps! 回答1: NOTE : I highly encourage you not to do this in your app, if you want to deploy it. This is only to show how we can do it.

Bluetooth HID Device & iOS textFields

天涯浪子 提交于 2019-11-28 06:46:41
问题 We are using a BT device, which acts as a keyboard, to talk to the iPad. We want this bluetooth device to talk to 1 field in our app. (Which is on it's own view) All other textFields/areaFields we want to display the virtual keyboard. Is this possible? Whenever the BT device is paired it disabled the on screen keyboard. We thought of turning bluetooth off before the view with the 1 field that needs its input from the device is displayed and then turning it back on when the view is removed,

《effective C++》总结【1】

你。 提交于 2019-11-28 06:17:50
最近开始看c++经典著作《effective c++》,总结了一些要点。 关键字的使用 1 自定义类的构造函数应该加上explicit,目的是为了防止隐式转换。除非有好的理由说明需要隐式转换,否则默认加上explict防止出现没有预料到的情况。 2 对于内置类型(int, double)和STL来说,pass-by-value比pass-by-reference更加高效,但是对于自定义的类,pass-by-reference比pass-by-value更加高效。 3 由于#define定义的宏常量可能没有进入到记号表,导致追踪不到。我是从来没遇到过这种情况,但是作者还是建议在众多场合 不要 使用#define。 定义常量整数或实数时,尽量用const int或const double代替。这会导致更少量的码。 定义常量指针时,要用两次const。const char* authorname = “scott meyers”。 定义类中的常量时,还要用static修饰。 定义类中的数组时,必须要定义常量,这时如果编译器不允许在类内声明时定义常数,就可以用enum代替。例如   class GamePlayer{   private:     enum { NumTurns = 5};     int scores[NumTurns];   }   enum的行为比较像

Calling a base class method in a template virtual class hierarchy

孤街浪徒 提交于 2019-11-28 04:52:20
问题 Let's say I have the following class hierarchy: template< class T > class TestBase { public: virtual T const & do_foo() = 0; }; template< class T > class TestDerived : public virtual TestBase< T > { public: virtual int do_bar() { return do_foo() + 1; } }; GCC spits out the following: error: there are no arguments to ‘do_foo’ that depend on a template parameter, so a declaration of ‘do_foo’ must be available [-fpermissive] note: (if you use ‘-fpermissive’, G++ will accept your code, but