C++相談室 part92
■ このスレッドは過去ログ倉庫に格納されています
0036デフォルトの名無しさん
2011/11/07(月) 13:01:44.70struct Base {
Base* duplicate () { return duplicate_xxx(); };
void put() const { put_(); }
private:
virtual Base* duplicate_xxx () { return this; };
virtual void put_() const { std::puts("Base::put"); }
};
struct Derived : public Base {
Derived* duplicate () { return duplicate_xxx(); };
void put() const { put_(); }
private:
virtual Derived* duplicate_xxx () { return this; };
virtual void put_() const { std::puts("Derived::put"); }
};
int main()
{
Base* b = new Derived;
Derived* d = new Derived;
b->duplicate()->put();
d->duplicate()->put();
delete d;
delete b;
}
■ このスレッドは過去ログ倉庫に格納されています