Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interface with base class
Message
From
05/08/2009 04:26:34
 
 
To
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:
01416160
Views:
56
>>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'.
>
Hi,
See my reply to Bonnie.
I understand the nature of the complaint but not why the compiler needs to make it :-}
Best,
Viv
Previous
Reply
Map
View

Click here to load this message in the networking platform