Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C# problem with inherited constructors


ghost's Avatar
0 0
{
player = thePlayer;
}```

Ok, so, I believe the code above should be a constructor with the inherited abilities of another program; however, it is giving me compile errors (it says I should add a semicolon).

If anyone can help me, and/or needs to see the whole 200 line program, tell me and I will PM you.

ghost's Avatar
0 0

Would a constructor be able to inherit from another class? The way it usually works, just classes can inherit (extend) other classes, or maybe implement interfaces.


ghost's Avatar
0 0

Yes, but, this constructor is in a class inherited from another with the constructor I am trying to inherit. I don't think the compiler is recognizing it as a constructor.


ghost's Avatar
0 0

After googling for C# syntax I understand more of what you are trying to do. What you have written seems correct to me, by comparing to this example code found on google:

{
    public myBaseClass()
    {
        // Code for First Base class Constructor
    }

    public myBaseClass(int Age)
    {
        // Code for Second Base class Constructor
    }

    // Other class members goes here
}

public class myDerivedClass : myBaseClass
// Note that I am inheriting the class here.
{
    public myDerivedClass()
    {
        // Code for the First myDerivedClass Constructor.
    }

    public myDerivedClass(int Age):base(Age)
    {
        // Code for the Second myDerivedClass Constructor.
    }

    // Other class members goes here
}```

So maybe there is something wrong in your code just over/under the constructor? 
At least here is a small guide on constructors and inheritance in C#:
http://www.codeproject.com/dotnet/ConstructorsInCSharp.asp