Capture vector by reference

I have a vector containing values of a custom class and I’m trying to capture it by reference in a touchListener but none of the values inside of the vector are getting captured.

vector<Player> players;
//add some stuff to players

CCLOG("%i", players.size()); //logs 4
auto touchListener = EventListenerTouchAllAtOnce::create();
touchListener->onTouchesBegan = [&](const std::vector<Touch*> &touches, Event* event) {
	for(int i = 0; i < touches.size(); ++i){
		auto p = touches[i]->getLocation();
		CCLOG("%i", players.size()); //logs 0 when it should log 4
		for (Player j : players) {
                          //do some stuff
                }
         }
}
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

Any help would be greatly appreciated

Try like this,
touchListener->onTouchesBegan = [&, players](const std::vector<Touch*> &touches, Event* event) {

For more details: http://www.cprogramming.com/c++11/c++11-lambda-closures.html

I don’t want to capture players by copy but rather capture it by reference.

You must declare vector<Player> players; in .h file then, it will work.