C++
openFrameworks

C++でのremoveChildAtの実装例

More than 3 years have passed since last update.
vector<flash::DisplayObject*> children;

flash::DisplayObject* DisplayObjectContainer::removeChildAt(const int& index) {
    //対象の子がなかったらエラー
    if(index < 0 || index > children.size() - 1) throw "DisplayObjectContainer::removeChildAt\n";

    DisplayObject* child = children[index];
    //ステージとの参照を切る
    child->stage(NULL);
    //親コンテナとの参照を切る
    child->parent(NULL);
    //配列から削除
    children.erase(children.begin() + index);

    return child;
}