Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello
How i can pass stack as parameter to function

void sor (stack<int> s)
{
////////
}

Thank foremost
Posted
Comments
Kornfeld Eliyahu Peter 5-Jan-16 15:49pm    
And do what with the stack?
Sergey Alexandrovich Kryukov 5-Jan-16 15:56pm    
Right question, but it also depends on what is "stack". Please see Solution 1.
—SA
Gnasani 7-Jan-16 13:02pm    
Nothing just i want to know how pass stack to function

1 solution

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:
C++
void someFunction(stack * s) { /* ... */ }
void someOtherFunction(stack & s)  { /* ... */ }
// and the like...

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
 
Share this answer
 
v3
Comments
Gnasani 7-Jan-16 12:59pm    
thanks for answer to my question
Sergey Alexandrovich Kryukov 7-Jan-16 13:00pm    
You are welcome. And will you accept my answer formally? (It won't prevent others from adding their solutions.)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900