Java で独自のメソッドのいくつかを実装するインターフェイスを作成したい (ただし、以下に示すように、言語ではこれが許可されません)。
//Java-style pseudo-code
public interface Square {
//Implement a method in the interface itself
public int getSize(){//this can't be done in Java; can it be done in C++?
//inherited by every class that implements getWidth()
//and getHeight()
return getWidth()*getHeight();
}
public int getHeight();
public int getWidth();
}
//again, this is Java-style psuedocode
public class Square1 implements Square{
//getSize should return this.getWidth()*this.getHeight(), as implemented below
public int getHeight(){
//method body goes here
}
public int getWidth{
//method body goes here
}
}
独自のメソッドのいくつかを実装できる C++ のインターフェイスに相当するものを作成することは可能ですか?