简体   繁体   English

传递向量、队列和指向函数的指针

[英]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.我有一个函数myfunc() ,它需要参数std::vectorstd::queue和一个指向MyClass对象的指针。

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.如果没有找到,myClassObj 将被推送到队列中。 Otherwise, if the object is found, it will call another function to set the value of one of the parameters of the myClassObj.否则,如果找到该对象,它将调用另一个函数来设置 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. " "该函数应该搜索向量中的特定项。如果没有找到,则将 myClassObj 推送到队列中。否则,如果找到该对象,它将调用另一个函数来设置其中一项的值myClassObj 的参数。

In that case,在这种情况下,

  • take the vector by const&通过const& vector
  • the queue by & .....and queue& ..... 和
  • MyClass by & or pointer if you prefer that MyClass by &或指针,如果你愿意的话

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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