简体   繁体   中英

Passing a vector, queue, and pointer to a function

I have a function myfunc() which requires the parameters std::vector , std::queue , and a pointer to a MyClass object.

My function prototype is:

void myFunc(vector<MyClass*>, std::queue<MyClass*>, MyClass*);

I do not know if this is the proper prototype declaration or not.

To call my function, i do the following:

myFunc(myVector, myQueue, MyClassObj);

Again, im not sure this is entirely correct.

Lastly, my function is the following:

void myFunc(vector<MyClass*> myVector, std::queue<MyClass*> myQueue, MyClass* myClassObj)
{
   //do something
}

The function is supposed to search for a specific item in the vector. If it is not found, the myClassObj will be pushed to the queue. Otherwise, if the object is found, it will call another function to set the value of one of the parameters of the myClassObj.

Am i doing this correctly?

Thanks,

" The function is supposed to search for a specific item in the vector. If it is not found, the myClassObj will be pushed to the queue. Otherwise, if the object is found, it will call another function to set the value of one of the parameters of the myClassObj. "

In that case,

  • take the vector by const&
  • the queue by & .....and
  • MyClass by & or pointer if you prefer that

void myFunc(const vector<MyClass*>& myVector, std::queue<MyClass*>& myQueue, MyClass* myClassObj)
{
   //do something
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM