1
私はgolangのようなインタフェースを継承なしでC++で実装したいと思っています。C++のGim-likeのインタフェースを模倣する
例: -
//interface
struct Copyable{
void copy();
}
class Animal { //which implements the interface but doesn't inherit it.
....
void copy();
...
}
//consumer function
void Copy(Interface<Copyable> item){
item.copy();
}
int main(){
Animal a;
Copy(a);
}
これを実装する方法はありますか?
私はそれを期待していませんでした。しかし、複数の機能を持っている場合は、コピー可能で明瞭さを向上させることはありませんか? – Kavinda
ありがとうございます。はいコンセプトは私の考えと同じようです。 – Kavinda