のクローニング:私はBからFのクローンを作成するにはどうすればよいC++ - 私はそのような何か持っている基本クラス
Class Foo : Base {.."my stuph" ..};
int main() {
Base *b = new Base;
Foo f (b); <== **error** "invalid conversion from Base to Foo."
..
}
を?
「私の習慣」には、FooとBaseの間でトレーニングを行う機能があります。
他の人が書いている間は、Baseを変更することはできません。ところで
Foo(const Base & b)
: Base(b) // construct the base class, using its copy constructor
{
// plus, initialize Foo-specific member data here
}
:
おかげ
あなたはどうしたらいいですか:Foo * f = new Foo ;? –
ベースb =新しいベース;私に奇妙に見える – MadH
修正:見える* Java *私に。 –