如何传递对带参数的对象的引用

How do I pass in a reference to an object with arguments

#include "Data.h"

#include "Heap.h"

#include "PQ.h"
#include <iostream>

using namespace std;

//**********************************************************

void enqRequest(int newTrackNum, int currP ,int serialNumber,bool 
forwardDir, itemClass &item(int &newTrackNum,int &serialNumber))

{

cout << "Do the EnqRequest function."<<endl;
cout <<endl<<endl;
cout <<"Enter a New Track Number"<<endl;
cin >> newTrackNum;

if (newTrackNum >= 0 && newTrackNum <= 9) {




 cout <<"EnqRequest   "<<newTrackNum<<endl;
 cout << endl << endl;
 cout <<"Current Position: .............."<<currP<<endl;
 cout <<"Current Direction: ............."<<endl;
 cout <<"Request was Enqueued in the: ..."<<endl;
 cout <<"Number of Request is: ......"<<endl;
 cout      <<"======================================================================    ======"<<endl;
    }
    else
        cout <<"Please Enter a number request between 0-9"<<endl;




}
//**********************************************************


int main(void) {


bool user = true;
bool fowardDir= true;
string commandUser;
int  trackNum, currentPosition,T;
T=0;

pqItemType forward;
pqItemType reverse;
itemClass item(int trackNum, int T);


currentPosition=0;
cout << "WELCOME TO THE DISK SCHEDULER"<<endl;
cout << "THE COMMANDS AVAILABLE TO YOU ARE \"EnqRequest\", \"ServeRequest\", \"PrintState\", AND \"Quit\"\n";
cin >> commandUser;
std::transform(commandUser.begin(), commandUser.end(), commandUser.begin(), ::toupper);

do{
    if ( commandUser == "ENQREQUEST" )
    {
        enqRequest(trackNum,currentPosition,T,fowardDir,&item);


        cout << "THANK YOU FOR USING THE DISK SCHEDULER"<<endl;
        cout << "THE COMMANDS AVAILABLE TO YOU ARE \"EnqRequest\", \"ServeRequest\", \"PrintState\", AND \"Quit\"\n";
        cin >> commandUser ;
        std::transform(commandUser.begin(), commandUser.end(), commandUser.begin(), ::toupper);
    }
  else
    {
        cout << "Please, enter a command" << endl;
        cin >> commandUser;
        std::transform(commandUser.begin(), commandUser.end(), commandUser.begin(), ::toupper);
    }

}while (user);


return 0;
}

我有一个带参数的对象项 (int trackNum, int T);我正在尝试将对此对象的引用传递给 enqRequest 函数和其他尚未创建的函数。当我传递对象引用时,我是否还必须专门传递对象本身使用的参数?例如

void enqRequest(itemClass &item(int &newTrackNum,int &serialNumber))

以下对象构造错误: itemClass item(int trackNum, int T);

应该是:

itemClass item(trackNum, T);

这假设您有一个构造函数将 trackNum、T 参数分配给 itemClass 的 class 个成员。

如果要传递对此对象的引用,调用签名将是:

enqRequest(trackNum,currentPosition,T,fowardDir,item);

函数 enqRequest 需要:

void enqRequest(int newTrackNum, int currP ,int serialNumber,bool 
forwardDir, itemClass &item)
{
cout << "Do the EnqRequest function."<<endl;
cout <<endl<<endl;
cout <<"Enter a New Track Number"<<endl;
cin >> newTrackNum;

if (newTrackNum >= 0 && newTrackNum <= 9) {
 cout <<"EnqRequest   "<<newTrackNum<<endl;
 cout << endl << endl;
 cout <<"Current Position: .............."<<currP<<endl;
 cout <<"Current Direction: ............."<<endl;
 cout <<"Request was Enqueued in the: ..."<<endl;
 cout <<"Number of Request is: ......"<<endl;
 cout      <<"======================================================================    ======"<<endl;
    }
    else
        cout <<"Please Enter a number request between 0-9"<<endl;




}