Base Class Doesn't Contain Parameterless Constructor?

前端 未结 6 1908
别那么骄傲
别那么骄傲 2021-02-01 01:11

I\'m making my constructors a bit more strict by removing some of my empty constructors. I\'m pretty new to inheritance, and was perplexed with the error that I got: Base Class

6条回答
  •  有刺的猬
    2021-02-01 01:26

    when you create the object of your derived class,your base class constructor gets called automatically.So at the time you create your derived class object,and your derived class object has not constructor taking one or more arguments, there will be nothing to pass to the base class constructor that wants one argument. so to do that, you need to pass something to the base class constructor as follows:

    Class A{
        //No empty constructor for A
        //Blah blah blah...
    }
    
    Class A2 : A{
        public A2():base(some parameter)
    }
    

提交回复
热议问题