且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将堆栈作为参数传递给fuction

更新时间:2022-06-27 02:39:56

这取决于你所谓的堆栈。如果这是一个数据结构( Stack(抽象数据类型) - ***,免费的百科全书 [ ^ ], Stack(C ++) - ***,免费的百科全书 [ ^ ], stack - C ++参考​​a> [ ^ ]) ,你***通过指针或引用传递它:

It depends on what you call "stack". If this is a data structure (Stack (abstract data type) - Wikipedia, the free encyclopedia[^], Stack (C++) - Wikipedia, the free encyclopedia[^], stack - C++ Reference[^]), you should better pass it by pointer or by reference:
void someFunction(stack * s) { /* ... */ }
void someOtherFunction(stack & s)  { /* ... */ }
// and the like...



我应该解释原因吗?如果你真的需要解释,我担心它应该解释编程的基础知识,这很难适合这个论坛的格式。



无论如何,这个阅读可能是有用的:

7.2。按值传递参数;学习C ++ [ ^ ],

7.3。通过引用传递参数;学习C ++ [ ^ ],

7.4。按地址传递参数;学习C ++ [ ^ ],

6.7。指针简介;学习C ++ [ ^ ]。



-SA


Should I even explain why? If you really need the explanation, I'm afraid it should go as far as explaining the very basics of programming, which can hardly fit the format of this forum.

Anyway, this reading could be useful:
7.2. Passing arguments by value; Learn C++[^],
7.3. Passing arguments by reference; Learn C++[^],
7.4. Passing arguments by address; Learn C++[^],
6.7. Introduction to pointers; Learn C++[^].

—SA