It depends a bit on what information you need exactly in the callback handler. But if you e.g. need to know the index of the button then you can just pass it as a constant to the connect function:
void buttonPressed(int index)
{
std::cout << "The " << index << "th button was pressed" << std::endl;
}
// The following goes in the for loop that you showed
b->connect("pressed", &buttonPressed, i);