cocos2dx c ++将向量附加到向量

时间:2016-07-12 06:50:49

标签: cocos2d-x

如何连接两个cocos2d :: Vector s?

cocos2d::Vector<FiniteTimeAction*> V1;
cocos2d::Vector<FiniteTimeAction*> V2;

我想将V2附加到V1;

1 个答案:

答案 0 :(得分:2)

cocos2d :: Vector重载了pushBack,它接受一个向量并将其推回到另一个向量。

V1.pushBack(V2);

CCVector.h

    /** Adds a new element at the end of the Vector. */
    void pushBack(T object)
    {
        CCASSERT(object != nullptr, "The object should not be nullptr");
        _data.push_back( object );
        object->retain();
    }

    /** Push all elements of an existing Vector to the end of current Vector. */
    void pushBack(const Vector<T>& other)
    {
        for(const auto &obj : other) {
            _data.push_back(obj);
            obj->retain();
        }
    }

P.S不清楚为什么他们不在重载的pushBack中使用pushBack(T对象)(co​​nst Vector&amp; other)