0

Following code throws following errors on line with "function(iteratorIndex);":

  • must use '.' or '->' to call pointer-to-member function
  • called object type 'void (MainWindow::)(QMap<QPushButton, QHBoxLayout*>::const_iterator&) is not a function or function pointer
void MainWindow::ForEachInLayoutMap(void(MainWindow::*function)(QMap<QPushButton*, QHBoxLayout*>::const_iterator&))
{
    QMap<QPushButton*, QHBoxLayout*>::const_iterator iteratorIndex = deleteButtonToIngredientLayoutMap.constBegin();
    QMap<QPushButton*, QHBoxLayout*>::const_iterator endIterator = deleteButtonToIngredientLayoutMap.constEnd();
        while (iteratorIndex !=endIterator)
        {
          function(iteratorIndex);
          iteratorIndex++;
        }
}

Any ideas how should I solve this?

  • 2
    What you have is a method pointer. To invoke a method, you need an instance of the class the method belongs to. – user4581301 May 06 '22 at 21:12
  • 1
    Here's some really good reading on the topic that should sort you out: https://isocpp.org/wiki/faq/pointers-to-members – user4581301 May 06 '22 at 21:12

0 Answers0