Stack topElem function question

This is a discussion on Stack topElem function question within the C++ Programming forums, part of the General Programming Boards category; I have a function to get the top element from a stack...but I'm having a problem calling it Code: void ...

  1. #1
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101

    Stack topElem function question

    I have a function to get the top element from a stack...but I'm having a problem calling it

    Code:
    void stack::topElem(el_t& elem)
    {
    	if(isEmpty())
    	{
    		stackError("stack is empty");
    	}
    	else
    	{
    		elem = el[top];
    	}
    	
    }
    problem is I didn't write this the professor did...I would've just returned something but I have no idea what to put in the parameters. I though possibly this:

    i
    Code:
    f ((let != '*') && (let != '+') && (let != '-') && (let != '/'))
          { 
    		  thisStack.push(int(mystring[i]));
          }
    	  else
    	  {
    		  thisStack.pop(thisStack[thisStack.topElem(?????)]);
    	  }

    Those ??? symbolize my confusion. Any help would be appreciated....

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    As you can see by the "&" in the parameter declaration, the function can change the parameter passed in. So whatever you want the function to change, you pass in.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 06:32 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. stack make file problem
    By puckett_m in forum C Programming
    Replies: 2
    Last Post: 11-22-2001, 11:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21