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