こんにちは、私は name() と呼ばれるメソッドを持つ要素 T (いくつかのタイプ T) を出力するための mixin クラス (非常に考案された) を作成しました。
これが C++ で実装する正しい方法と見なされるかどうか疑問に思っていますか?
どんなコメントでも大歓迎です。
template<class T>
struct name_method_printer_to_console_mixin{
void print() const{
auto& that = static_cast<T const&>(*this);
cout << "Mixin printing name which is: " << that.name() << endl;
}
};
class customer : public name_method_printer_to_console_mixin<customer>{
public:
customer(){}
customer(string const &name) : name_(name){}
string const & name() const{
return name_;
}
private:
string name_;
};
ブレア