Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3356538
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:31:29+00:00 2026-05-18T02:31:29+00:00

I am trying to call a function for my stack class. If I have

  • 0

I am trying to call a function for my stack class. If I have all of the functions within the main file the project works, however, when called from the class it says the the Error: identifier “function name” is undefined. I think it is a simple syntax error, but i can’t find it.

main.cpp

#include<iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "stack.h"


#define MAX 10
#define EMPTY -1

struct stack
{
char data[MAX];
int top;
 };


int mystack::isempty(struct stack *s)
{
return (s->top == EMPTY) ? 1 : 0;
}

void mystack::emptystack(struct stack* s)
{
s->top=EMPTY;
}

void mystack::push(struct stack* s,int item)
{
if(s->top == (MAX-1))
{
    printf("\nSTACK FULL");
}
else
{
    ++s->top;
    s->data[s->top]=item;
}
}

char mystack::pop(struct stack* s)
{
char ret=(char)EMPTY;
if(!isempty(s))
{
    ret= s->data[s->top];
    --s->top;
}
return ret;
}

void mystack::display(struct stack s)
{
while(s.top != EMPTY)
{
    printf("\n%d",s.data[s.top]);
    s.top--;
}
}



int isoperator(char e)
{
if(e == '+' || e == '-' || e == '*' || e == '/' || e == '%' || e == '^')
    return 1;
else
    return 0;
}


int priority(char e)
{
int pri = 0;
if(e =='%' || e == '^')
    pri = 3;
else
{
    if (e == '*' || e == '/' || e =='%')
    pri = 2;
    else
    {
    if(e == '+' || e == '-')
        pri = 1;
    }
}

return pri;
}

void infix2postfix(char* infix, char * postfix, int insertspace)
{
char *i,*p;
struct stack X;
char n1;
emptystack(&X); // any time a class like this is called it says Error: identifier "emptystack"
                                                             // is undefined
i = &infix[0];
p = &postfix[0];

while(*i)
{
    while(*i == ' ' || *i == '\t')
    {
        i++;
    }

    if( isdigit(*i) || isalpha(*i) )
    {
        while( isdigit(*i) || isalpha(*i))
        {
            *p = *i;
            p++;
            i++;
        }

        if(insertspace)
        {
            *p = ' ';
            p++;
        }

    }

    if( *i == '(' )
    {
        push(&X,*i);
        i++;
    }

    if( *i == ')')
    {
        n1 = pop(&X);
        while( n1 != '(' )
        {
            *p = n1;
            p++;

            if(insertspace)
            {
                *p = ' ';
                p++;
            }

            n1 = pop(&X);
        }
        i++;
    }

    if( isoperator(*i) )
    {
        if(mystack::isempty(&X))
            push(&X,*i);
        else
        {
            n1 = pop(&X);
            while(priority(n1) >= priority(*i))
            {
                *p = n1;
                p++;

                if(insertspace)
                {
                    *p = ' ';
                    p++;
                }

                n1 = pop(&X);
            }
            push(&X,n1);
            push(&X,*i);
        }
        i++;
    }
}
while(!isempty(&X))
{
    n1 = pop(&X);
    *p = n1;
    p++;

    if(insertspace)
    {
        *p = ' ';
        p++;
    }

}
*p = '\0';
}

int main()
{
char in[50],post[50];

strcpy(&post[0],"");
printf("Enter Infix Expression : ");
fflush(stdin);
gets(in);
infix2postfix(&in[0],&post[0],1);
printf("Postfix Expression is : %s\n",&post[0]);

return 0;
}

stack.h

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

using namespace std;

class mystack
{
public:


int isempty(struct stack *s);
void emptystack(struct stack* s);
void push(struct stack* s,int item);
char pop(struct stack* s);
void display(struct stack s);




};

I am using visual studio if that helps.

EDIT: added comment for clarity.

Thanks,
Ryan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:31:30+00:00Added an answer on May 18, 2026 at 2:31 am

    At a cursory glance, this function:

    void emptystack(struct stack* s)
    {
        s->top=EMPTY;
    }
    

    Is missing the scope operator (::), so you probably intended to write it as:

    void mystack::emptystack(struct stack* s)
    {
        s->top=EMPTY;
    }
    

    I’m not sure if that’s your problem though, since “I’m trying to call a function” is a bit vague. You might want to narrow down precisely where the error is occurring, then edit your question with additional information.


    Edit: In looking at your implementation a bit more, I’m not sure why you created the mystack class at all. It looks like you just want to define a bunch of functions that operate on your stack struct, which doesn’t require a class definition. If you want to do it this way for some unusual reason, then you’ll have to instantiate a mystack object before you can call its member functions. Something of the nature:

    mystack * myStackObj = new mystack();
    myStackObj->emptystack(&X);
    

    Though I’m not sure why you would want to do this. The other alternative is to roll your stack struct into the class instead, either by making the whole struct a member of the class or by simply adding data and top to the class. Then if you instantiated a mystack object it would have the data of the stack and could call methods on its own data. I’d also suggest looking at a tutorial/documentation/book related to C++ classes and their usage. Here’s one, but there are undoubtedly plenty of others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to call a setTimeout from within a setInterval callback: function callback()
I'm trying to dynamically define functions that call through to another function that takes
I'm trying to call a function after I load some XML into Actionscript, and
I'm trying to call the OpenThemeData (see msdn OpenThemeData ) function but I couldn't
Has anyone seen this error when trying to call an external C function from
I am trying to use some pinvoke code to call a C function. The
When trying to call Close or Dispose on an SqlDataReader i get a timeout
I'm trying to call an Antlr task in my Ant build.xml as follows: <path
I am trying to call a shell script that sets a bunch of environment
I am trying to call a webservice using ssl. How do i get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.