提问者:小点点

堆栈和队列是否像C++中的数组一样传递?


我想问这个问题,因为我们可以改变传递给函数的数组的内容,而不需要传递引用,但这与堆栈和队列不同。


共1个答案

匿名用户

您需要理解,数组基本上是一个内存位置序列,可以用指针直接访问。 与此相反,堆栈队列是容器,您可以实例化它们。

void foo(std::stack<int> st) { //pass by value
//whatever
}

void foo(std::stack<int>& st) { //pass by reference
//whatever
}

void foo(std::stack<int>* st) { //pass by pointer
//whatever
}

std::stack<int> stack; //instantiation
foo(stack); //calling the function
foo(&stack); //when you need to pass by pointer (never used)

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(堆栈|队列|c++|中|数组|传递)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?