void function(typeA* ptr_to_A) {
if (!ptr_to_A) {
typeB B; // typeB is a derived class of typeA
ptr_to_A = &B;
}
do_stuff_to_ptr_to_A(ptr_to_A);
// my hope is that B is still in scope here so that this function will operate on my B object (which is on the stack) which only gets created if ptr_to_A was initially NULL
}
この関数は、私が思っていること (私がやりたいこと) を実行しますか? つまり、引数がヌル ポインターの場合にのみスタックに B を割り当てますか?