- Home /
Question by
awplays49 · Nov 05, 2015 at 02:22 AM ·
derived-class
How to create a class constructor that derives from a derived class?
Like this...?
public class DerivedFromDerived (int i) : base (int j) : base (int k) {
Comment
Answer by Dave-Carlile · Nov 05, 2015 at 02:33 AM
The derived class already calls the base constructor in its constructor - you have to pass all of the parameters to the derived constructor and pass the appropriate ones up the chain...
public class ClassA
{
public ClassA(int k)
{
// do something with k
}
}
public class ClassB : ClassA
{
public ClassB(int j, int k) : base(k)
{
// do something with j
}
}
public class ClassC : ClassB
{
public ClassC(int i, int j, int k) : base(j, k)
{
// do something with i
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612043958im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Derives from MonoBehaviour or Component or is an interface. Error 2 Answers
Have array of Unit; Unit is base Class; How to access derieved class functions??? 1 Answer
Is it possible to change value on base class when the same field gets changed on it's derived class 0 Answers
CustomPropertyDrawer for derived class? 1 Answer
How to access derived class members from base class type 1 Answer