Call base function then inherited function

前端 未结 6 1210
野性不改
野性不改 2020-12-01 02:48

I have a base class and a class inheriting base. The base class has several virtual functions that the inherited class may override. However, the virtual functions in the ba

6条回答
  •  没有蜡笔的小新
    2020-12-01 03:21

    What do you think of this?

    class myBase
    {
        public void myFunctionWrapper()
        {
            // do stuff that must happen first
            // then call overridden function
            this.myFunction();
        }
    
        public virtual void  myFunction(){ 
           // default implementation that can be overriden
    
        }
    
    }
    
    class myInherited : myBase
    {
        public override void myFunction()
        { 
    
        }
    }
    

提交回复
热议问题