Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,

like image 465
Noobgineer Avatar asked Apr 24 '26 08:04

Noobgineer


1 Answers

"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
}
like image 178
WhiZTiM Avatar answered Apr 25 '26 22:04

WhiZTiM