Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interface with base class
Message
From
05/08/2009 03:04:54
 
 
General information
Forum:
ASP.NET
Category:
Object Oriented Programming
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01416072
Message ID:
01416156
Views:
72
>I thought I'd used this sort of construct before. But the compiler insists that the type of Parent in Test must be BaseClass.
public interface ITest
>    {
>        BaseClass Parent { get; }
>    }
>
>    public class BaseClass {}
>
>    public class DerivedClass : BaseClass{}
>
>    public class Test : ITest
>    {
>        public DerivedClass Parent
>        {
>            get {return new DerivedClass(); }
>        }
>    }
Am I cracking up?

Viv,

I agree with Bonnie

Your interface says the return type should be BaseClass and you're returning another type. iow the signature of the interface does not match

See last line of error message ( I have taken my namespace out to make it clearer)
Error	1	'Test' does not implement interface member 'ITest.Parent'.
 'Test.Parent' cannot implement 'ITest.Parent' because it does not have the matching return type of 'BaseClass'.
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform