virtual

Virtual Functions C#

你说的曾经没有我的故事 提交于 2019-11-29 10:25:01
问题 I understand what a virtual function is. But what I don't get is how do they work internally? class Animal { virtual string Eat() { return @"Eat undefined"; } } class Human : Animal { override string Eat() { return @"Eat like a Human"; } } class Dog : Animal { new string Eat() { return @"Eat like a Dog"; } } static void Main() { Animal _animal = new Human(); Console.WriteLine(_animal.Eat()); _animal = new Dog(); Console.WriteLine(_animal.Eat()); } Output for the above gives: Eat like a Human

Reflection says that interface method are virtual in the implemented type, when they aren't?

吃可爱长大的小学妹 提交于 2019-11-29 09:26:09
I have the following code in an unit test public bool TestMethodsOf<T, I>() { var impl = typeof(T); var valid = true; foreach (var iface in impl.GetInterfaces().Where(i => typeof(I).IsAssignableFrom(i))) { var members = iface.GetMethods(); foreach (var member in members) { Trace.Write("Checking if method " + iface.Name + "." + member.Name + " is virtual..."); var implMember = impl.GetMethod(member.Name, member.GetParameters().Select(c => c.ParameterType).ToArray()); if (!implMember.IsVirtual) { Trace.WriteLine(string.Format("FAILED")); valid = false; continue; } Trace.WriteLine(string.Format(

RabbitMQ用户角色及权限控制

一个人想着一个人 提交于 2019-11-29 09:02:40
RabbitMQ的用户角色分类: none、management、policymaker、monitoring、administrator user 有5种 tags : management :访问 management plugin; policymaker :访问 management plugin 和管理自己 vhosts 的策略和参数; monitoring :访问 management plugin 和查看所有配置和通道以及节点信息; administrator :一切权限; None :无配置 RabbitMQ各类角色描述: none 不能访问 management plugin management 用户可以通过AMQP做的任何事外加: 列出自己可以通过AMQP登入的virtual hosts 查看自己的virtual hosts中的queues, exchanges 和 bindings 查看和关闭自己的channels 和 connections 查看有关自己的virtual hosts的“全局”的统计信息,包含其他用户在这些virtual hosts中的活动。 policymaker management可以做的任何事外加: 查看、创建和删除自己的virtual hosts所属的policies和parameters monitoring

当选微软MVP 2012 Virtual Machine

早过忘川 提交于 2019-11-29 08:56:08
当选微软MVP 2012 Virtual Machine 约是昨天的晚上十点十八分左右,我收到了微软MVP当选的通知 其实我在晚上八点的时候,看过信箱,没看到信,想说落选了,就跑去打个电动发泄一下XDDD 回来查个数据,想说去信箱看看(不死心啊…),就看到了这封…XD 其实得到这个奖项,我是有些意外的,我一直认为我应该不会中 因为我博客成立的时间并不常、论坛回复也不多,近三百篇,一百多篇的解答,我想应该不高 我寄报名信的冲动,其实是那天参加版聚,在领奖过程中宣示参加的XDD 不过参加还是个人意愿啦,只是觉得说出来就要做得到,才符合个人原则嘛:P 论坛中很多的回复,都是经验,只是因为任职的公司,做的很多都是比较机密的单位 所以没办法截图、分享整个过程的经验,我也只能尽可能地还原情境、描述当时的情况,分享我的解决方法 所以,可能有些人会觉得这个博客,写的解决方法很少,Step By Step的安装分享偏多 但是我会在论坛上,透过大家的问题,去分享我的经验,也会引导各位一些概念,也会解释一些概念上的问题 也感谢MVP Rico前辈在我留言给他之后,他给我的一些鼓励,这是他的博客,写得很棒 因为我本身是SI工程师的关系,所以很多都会涉猎一些 未来我会继续延续我的热情,我不会让MVP的证书出现在鸡排摊上面的XDDD 各位路人甲,看到文章,觉得有问题或有疑问,可以直接留个言给我

小结

南楼画角 提交于 2019-11-29 08:21:28
. 类成员函数的重载、覆盖和隐藏区别? 答:1.成员函数被重载的特征: (1)相同的范围(在同一个类中); (2)函数名字相同; (3)参数不同; (4)virtual 关键字可有可无。 2.覆盖是指派生类函数覆盖基类函数,特征是: (1)不同的范围(分别位于派生类与基类); (2)函数名字相同; (3)参数相同; (4)基类函数必须有virtual 关键字。 3.“隐藏”是指派生类的函数屏蔽了与其同名的基类函数,规则如下: (1)如果派生类的函数与基类的函数同名,但是参数不同。此时,不论有无virtual关键字,基类的函数将被隐藏(注意别与重载混淆)。 (2)如果派生类的函数与基类的函数同名,并且参数也相同,但是基类函数没有virtual 关键字。此时,基类的函数被隐藏(注意别与覆盖混淆)。 重载(overload)和重写(overried,有的书也叫做“覆盖”)的区别? 答:从定义上来说: 重载:是指允许存在多个同名函数,而这些函数的参数表不同(或许参数个数不同,或许参数类型不同,或许两者都不同)。 重写:是指子类重新定义父类虚函数的方法。 从实现原理上来说: 重载:编译器根据函数不同的参数表,对同名函数的名称做修饰,然后这些同名函数就成了不同的函数(至少对于编译器来说是这样的)。如,有两个同名函数:function func(p:integer):integer

面试问题之C++语言:Overload、Override及Overwirte的区别

社会主义新天地 提交于 2019-11-29 05:08:44
Overload(重载) :在C++程序中,可以将语义、功能相似的几个函数用同一个名字表示,但参数或返回值不同(包括类型、顺序不同),即函数重载。   特点:   (1)相同的范围(在同一个类中)   (2)函数名字相同   (3)参数不同   (4)virtual关键字可有可无 Override(覆盖) :是指派生类函数覆盖基类函数。   特点:   (1)不同的范围(分别位于派生类与基类)   (2)函数名相同   (3)参数相同   (4) 基类函数必须有virtual关键字 Overwrite(重写) :是指派生类的函数屏蔽了与其同名的基类函数,规则如下:   (1)如果派生类的函数与基类的 函数同名 ,但是 参数不同 。 此时, 不论有无virtual 关键字,基类的函数将被隐藏(注意别与重载混淆)。   (2)如果派生类的函数与基类的 函数同名 ,并且 参数也相同 ,但是基类函数 没有virtual 关键字。此时,基类的函数被隐藏(注意别与覆盖混淆)。 来源: https://www.cnblogs.com/yichengming/p/11456468.html

Requiring virtual function overrides to use override keyword

混江龙づ霸主 提交于 2019-11-29 04:38:58
问题 C++11 added override to ensure that member functions you write that you intend to override base-class virtual functions actually do (or won't compile). But in a large object hierarchy, sometimes you could accidentally end up writing a member function that overrides a base-class virtual when you didn't intend it! For instance: struct A { virtual void foo() { } // because obviously every class has foo(). }; struct B : A { ... }; class C : B { private: void foo() { // was intended to be a

Template definitions outside class body

非 Y 不嫁゛ 提交于 2019-11-29 03:49:00
Is it O.K. to define virtual function of class template outside its body? Virtual function can not be inlined, but to avoid multiple definitions in compilation units they shall be marked inline (assuming that template headers will be included in multiple source files). On the other hand compiler is free to ignore inline , so this seems valid. By an example, is the code below correct: template <typename T> class C { public: virtual void f(T val); }; template <typename T> inline void C<T>::f(T val) { //definition } ? BTW gcc (3.4.2) allows to omit inline before definition of function f(T val)

Android Creating a memory resident input file that can be attached to an email

夙愿已清 提交于 2019-11-29 03:47:26
The final objective will be clear shortly. I want to create a file object and instead of getting data from a real physical file I want to provide the buffer myself. Then, I want to use this file, which does not really exist in the sdcard or anywhere outside my app, give it a name and send it by email as an attachment (using the EXTRA_STREAM). I found the following bit of code, by Adriaan Koster (@adriaankoster), the post Write byte[] to File in Java // convert byte[] to File ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); File

Override number of parameters of pure virtual functions

时光毁灭记忆、已成空白 提交于 2019-11-29 03:18:13
I have implemented the following interface: template <typename T> class Variable { public: Variable (T v) : m_value (v) {} virtual void Callback () = 0; private: T m_value; }; A proper derived class would be defined like this: class Derived : public Variable<int> { public: Derived (int v) : Variable<int> (v) {} void Callback () {} }; However, I would like to derive classes where Callback accepts different parameters (eg: void Callback (int a, int b)) . Is there a way to do it? Matthieu M. This is a problem I ran in a number of times. This is impossible, and for good reasons, but there are ways