如何调用抽象基类的虚函数 [英] How to call virtual function of a abstract base class

查看:97
本文介绍了如何调用抽象基类的虚函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



Hi All,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    abstract class A
    {
        public virtual void Meto()
        {
            Console.WriteLine("A");
        }
    }

    class B : A
    {
        public override void Meto()
        {

            Console.WriteLine("B");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            A b = new B();


        }
    }
}





现在我想要打电话给A级的Meto。



有没有办法实现这个目的。



Now i want to call Meto of Class A.

Is there any way to achieve this.

推荐答案

我想你将从Microsoft文档中找到此链接中的答案:

http://msdn.microsoft.com/en-us/library/k535acbf%28v=vs.71%29.aspx [ ^ ]
I think you''ll find the answer in this link from the Microsoft documentation:
http://msdn.microsoft.com/en-us/library/k535acbf%28v=vs.71%29.aspx[^]


abstract class A
    {
        public virtual void Meto()
        {
            Console.WriteLine("A");
        }
    }

    class B : A
    {
        public new void Meto()
        {

            Console.WriteLine("B");
        }
    }

    class Program
    {

        static void Main(string[] args)
        {
            
            A b = new B();
            b.Meto();//Print "A"

            B bb = new B();
            bb.Meto();//Print "B"


            Console.ReadLine();

        }
    }


这篇关于如何调用抽象基类的虚函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆