I dont no how to fix. Can someone help me out plz. (Please see the picture)
[IMG]http://i61.tinypic.com/2r2cfnq.png[/IMG]

#ifndef DYNINTSTACK_H
#define DYNINTSTACK_H

class DynIntStack
{
private:
    // Structure for stack nodes
    struct StackNode
    {
        int value;        // Value in the node
        StackNode *next;  // Pointer to the next node
    };

    StackNode *top;      // Pointer to the stack top

public:
    // Constructor
    DynIntStack()
    {  top = NULL; }

    // Destructor
    ~DynIntStack();

    // Stack operations
    void push(int);
    void pop(int &);
    bool bracketsame(char,char);
    bool balancedparantheses(string); //checks if parentheses are
    bool isEmpty();
};
#endif




#include "DynIntStack.h"
#include <iostream>
#include <string>
using namespace std;

// Main to run program
int main()
{
    string expression;

    cout<<"Enter an expression to check: ";
    cin>>expression;

    if(DynIntStack::balancedparantheses(expression))
        cout<<"Balanced expression \n";

    else
        cout<<"Expression is not balanced \n";
}
bool bracketsame(char opening,char closing) // function checks if opening and closing brackets are same
{
    if(opening == '(' && closing == ')') return true;
    else if(opening == '{' && closing == '}') return true;
    else if(opening == '[' && closing == ']') return true;
    return false;
}
bool balancedparantheses(string exp) //checks if parentheses are
{                                    //balanced or not
    stack<char> StackNode;
    for(int i =0;i<exp.length();i++)
    {
        if(exp[i] == '(' || exp[i] == '{' || exp[i] == '[')
            StackNode.push(exp[i]);
        else if(exp[i] == ')' || exp[i] == '}' || exp[i] == ']')
        {
            if(StackNode.empty() || !bracketsame(StackNode.top(),exp[i]))
                return false;
            else
                StackNode.pop();
        }
    }
    return StackNode.empty() ? true:false;
}
    It my first accest to member. I think thtat acesst it right. But didnt work I am stuck. Can someone plz show how please.

Ah, I think I see the problem: the function is a method of the clas, but you did not scope the function as being part of the class in the implementation. When you define a method for a class, and do not implement it inline (which is how most method should be the done - inlining should only be used for one or two line functions), the corresponding implementation has to have the name of the class and the scope operator (::) before the function name. In this case, it should be:

bool DynIntStack::balancedparantheses(string exp) // etc.

You would do the same with bracketname() as well.

I would actually recommend having these two functions in a third file, as the implementation file, and link the file with the program file when you compile it. If you are using an IDE such as Visual Studio or Code::Blocks, it should be sufficient to simply have the implementation file in the project file (under Solution Explorer, in Visual Studio). This lets you treat the class like any other library.

This article has been dead for over six months. Start a new discussion instead.