ここに という名前のインターフェースがありますIFish
。から派生したクラスがプロパティを実装する必要がないWalkingFishCommon
ように、不完全な実装を提供する抽象クラス ( ) でそれを派生させたい:WalkingFishCommon
CanWalk
interface IFish
{
bool Swim();
bool CanWalk { get; }
}
abstract class WalkingFishCommon : IFish
{
bool IFish.CanWalk { get { return true; } }
// (1) Error: must declare a body, because it is not marked
// abstract, extern, or partial
// bool IFish.Swim();
// (2) Error: the modifier 'abstract' is not valid for this item
// abstract bool IFish.Swim();
// (3): If no declaration is provided, compiler says
// "WalkingFishCommon does not implement member IFish.Swim()"
// {no declaration}
// (4) Error: the modifier 'virtual' is not valid for this item
// virtual bool IFish.Swim();
// (5) Compiles, but fails to force derived class to implement Swim()
bool IFish.Swim() { return true; }
}
WalkingFishCommon から派生したクラスに強制的にメソッドを実装させるという目標を達成しながら、コンパイラを満足させる方法をまだ発見していませんSwim()
。Swim()
特に困惑するのは、(1) と (2) の間の差分です。コンパイラは、abstract とマークされていないという不平と、次の息で、abstract とマークできないという不平を交互に繰り返します。面白いエラー!
何か助けはありますか?