How to access member of Vector<MenuItem*>?

How to access member of Vector<MenuItem*>?
0.0 0

#1

I have a vector of MenuItem here:

cocos2d::Vector<cocos2d::MenuItem*> menuItems;

This vector contains 4 MenuItemImages :

menuItems.pushBack(myImage1);
menuItems.pushBack(myImage2);
menuItems.pushBack(myImage3);
menuItems.pushBack(myImage4);

Now I’m trying to set selected and set active these image items through a KeyBoard Listener :

auto keyBoardListener = EventListenerKeyboard::create();
keyBoardListener->onKeyPressed = [&](cocos2d::EventKeyboard::KeyCode keycode, Event* event)
{
	switch (keycode)
	{
	case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ARROW:
           // This should set myImage1 selected but it doesn't work
		menuItems[0]->selected(); 
           // This should activates myImage2  but it doesn't work
                menuItems[1]->active();
		break;
	}
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyBoardListener, this);

Visual Studio told me that There’s no operator “[]” matches these operands" .

Therefore, I dig into the CCVector.h and found that the operater [] function has been commented out with this comment:
// Don't uses operator since we could not decide whether it needs 'retain'/'release'.

So my question is, how could I access a member of the vector above? Your help is very much appriciated :D.


#2

menuitems.at(0)->active


#4

thanks a lot, can’t believe I don’t know the existance of at() function lol.