Call by ref or value

In the following code, For qpushbutton p ,im calling by reference or by calling value,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//in class declaration: QPushButton *adminMenuButton;
masterMenu::masterMenu(QWidget *parent)
        : QDialog(parent)
{
 createmasterMenu(adminMenuButton,"Admin");
}

void masterMenu::createmasterMenu(QPushButton *p,QString strCaption)
{
    p->setFixedHeight(40);
    p->setText("  " + strCaption);
    p->setFixedWidth(280);
    p->setFont(QFont("Trebuchet", 10, QFont::Bold));
    p->setStyleSheet("Text-align:centre");
    layout->addWidget(p);
}


createmasterMenu(adminMenuButton,"Admin"); is right or
createmasterMenu(&adminMenuButton,"Admin"); is right?


please clear my doubts
Thnks
You are calling by value, and your call is correct. The createmasterMenu() function takes a pointer to a push button object. Since your adminMenuButton variable is a pointer of that very type, then all is well.

If it were not a pointer, but the actual object itself, only then would you need to get its address with the & operator.

IIRC, Qt doesn't make use of "references" (in the C++ sense).

Hope this helps.
Topic archived. No new replies allowed.