virtual

More about Virtual / new…plus interfaces!

﹥>﹥吖頭↗ 提交于 2019-11-30 10:14:26
Yesterday I posted a question about the new/virtual/override keywords, and i learned a lot from your answers. But still i remain with some doubts. In between all the "boxes", i lost touch with what's really happening to the type's method tables. For instance: interface I1 { void Draw(); } interface I2 { void Draw(); } class A : I1, I2 { public void Minstance() { Console.WriteLine("A::MInstance"); } public virtual void Draw() { Console.WriteLine("A::Draw"); } void I2.Draw() { Console.WriteLine("A::I2.Draw"); } } class B : A, I1, I2 { public new virtual void Draw() { Console.WriteLine("B::Draw")

Internal Workings of C# Virtual and Override

时光毁灭记忆、已成空白 提交于 2019-11-30 09:09:11
The topic of how C# virtual and override mechanism works internally has been discussed to death amongst the programmers... but after half an hour on google, I cannot find an answer to the following question (see below): Using a simple code: public class BaseClass { public virtual SayNo() { return "NO!!!"; } } public class SecondClass: BaseClass { public override SayNo() { return "No."; } } public class ThirdClass: SecondClass { public override SayNo() { return "No..."; } } class Program { static void Main() { ThirdClass thirdclass = new ThirdClass(); string a = thirdclass.SayNo(); // this

C++ Virtual operator delete?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 08:32:26
Is it possible to have a virtual delete operator? I'm not talking destructor, I mean the actual operator overload. Minus the fact that it is (in most cases) a big bad idea to overload new and delete (Yes, I already know it's heresy), I want to know what kind of implications come from using a virtual delete operator. I'm thinking about trying to use a virtual delete, as sometimes I might have a child class that overloads delete, stored in a base class pointer. Technically, I don't really ever see this case coming to too much fruition, unless I have a tree of different node types (potentially

Redmine 学习笔记——安装篇

帅比萌擦擦* 提交于 2019-11-30 08:32:08
Redmine 学习笔记——安装篇 分类: 项目管理 2011-06-20 11:44 13人阅读 评论 (0) 收藏 举报 Redmine的介绍我就不写了,不知道的可以Google或者百度一下。 Redmine是做什么用的?简单点说,就是进行项目管理的一个系统,是B/S架构的。 由于这个系统的支撑系统比较多,安装相对复杂,经搜索,发现有一个叫BitNami的网站,提供了对于此类web service产品的捆绑打包安装,大大降低了安装难度。下面的说明也是基于BitNami的。 1、进入网址: http://bitnami.org/stack/redmine , 下载Redmine的安装程序。这里面包含几种不同的安装程序,我们主要关注安装于本机的“native”方式和安装在虚拟机中的“virtual”方 式。这两种安装方式的区别在于,后者让你下载一个linux的虚拟机镜像文件,里面已经安装好了Redmine,你只要启动虚拟机就可以了。该方式的好处 是完全不会影响你本地的系统。当然前者安装完后肯定会影响系统的,如果怕影响的话,可以放在沙盘里面。写此文章时Redmine的版本是1.2.0。 2、首先介绍使用虚拟机方式。虚拟机的镜像文件是VMWare的,有openSUSE和Ubuntu两种linux系统。看个人喜好下载其中一个就 行。如果系统没有VMWare的虚拟机程序,需要下载一个

Virtual Functions C#

為{幸葍}努か 提交于 2019-11-30 07:59:37
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 Eat undefined In the above code _animal is of type Animal which references a Human object or Dog object

C#中的虚函数virtual

≯℡__Kan透↙ 提交于 2019-11-30 07:55:02
简单介绍虚函数virtual 在某基类中声明 virtual 并在一个或多个派生类中被重新定义的成员函数称为虚函数。 虚函数的作用就是实现多态性(Polymorphism),多态性是将接口与实现进行分离。 C#作为完全面向对象语言,所有函数并不默认为virtual,但可以在基类中声明关键字virtual,就可以在其派生类中通过关键字override重写该函数。重写后的virtual函数依旧是virtual函数。由于virtual只对类中的实例函数成员有意义,所以成员字段和静态函数都不能声明为virtual,也不能与override和abstract一起用。 虚函数与一般函数的区别 一般函数在编译时就静态地编译到了执行文件中,其相对地址在程序运行期间是不发生变化的,也就是写死的!而虚函数在编译期间是不被静态编译的,它的相对地址是不确定的,它会根据运行时期对象实例来动态判断要调用的函数,其中声明时定义的类叫声明类,执行时实例化的类叫实例类。 使用虚函数virtual 1、当调用一个对象的函数时,系统会直接去检查这个对象声明定义的类,即声明类,看所调用的函数是否为虚函数。 2、如果不是虚函数,那么它就直接执行该函数。而如果有virtual关键字,也就是一个虚函数,那么这个时候它就不会立刻执行该函数了,而是转去检查对象的实例类。 3、在这个实例类里

Pure virtual functions in C++11

天涯浪子 提交于 2019-11-30 07:53:08
In C++98, the null pointer was represented by the literal 0 (or in fact any constant expression whose value was zero). In C++11, we prefer nullptr instead. But this doesn't work for pure virtual functions: struct X { virtual void foo() = nullptr; }; Why does this not work? Would it not make total sense? Is this simply an oversight? Will it be fixed? Because the syntax says 0 , not expression or some other non-terminal matching nullptr . For all the time only 0 has worked. Even 0L would be ill-formed because it does not match the syntax. Edit Clang allows = 0x0 , = 0b0 and = 00 (31.12.2013).

How can I browse a local virtual folder in C#?

99封情书 提交于 2019-11-30 05:47:50
问题 In my C# program I have to browse directories. So I use the method System.IO.Directory.GetFiles(directory) and it works well when directory is a real directory like "C:\Program File" but when it's a virtual directory (eg: librairie directory), directory value looks like this : "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\Pictures.library-ms" and I don't know how to browse it. 回答1: You need to translate the virtual path into a physical one, try: DirectoryInfo directoryInfo = new DirectoryInfo

Requiring virtual function overrides to use override keyword

∥☆過路亽.° 提交于 2019-11-30 05:36:35
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 private function local to C // not intended to override A::foo(), but now does } }; Is there some compiler

Convert character to the corresponding virtual-key code

故事扮演 提交于 2019-11-30 05:05:04
问题 Currently, I'm using the method VkKeyScan in the Win32 API to convert a character to its virtual-key code. But the problem that this seems to have is that, when i pass small alphabets, it works fine whereas when i pass in a capital alphabet, it doesn't return the appropriate key code and similarly with special characters like "(" or "}". How do i do this? Is there anyway for me to directly convert a string to its virtual equivalent without considering whether it contains capitalized or