468,733 Members | 2,232 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

Infix to Postfix Conversion Header File

Alright basically I just have one simple question. I can code perfectly fine and don't have any problems with the .cpp of the infix class but with my header I can't get anything to work really, any guideline as to how to start this would be great. It has to work with assign.cpp which is like this:
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.  
  4.    Infix infix;
  5.  
  6.    while (true)
  7.    {
  8.       //cout << "Enter an infix expression like 2*(3+4): " << endl;
  9.  
  10.       infix.read();
  11.  
  12.       if (cin.eof() )
  13.      break;
  14.  
  15.       infix.write();
  16.       cout << " = " << infix.evaluate() << endl;
  17.  
  18.    }  // end while
  19.  
  20.    return 0;
  21. }  // end main
I know this is sorta a dumb question but it's the only problem I'm really having.
Thanks
Mar 21 '07 #1
5 3267
horace1
1,510 Expert 1GB
I assume if you include the infix.cpp file it works OK but when you try to just include the infix.h and link the infix.cpp at link time you have problems??
have you an example of the header that is causing problems? or a list of error messages?
Mar 21 '07 #2
Basically it is telling me with the infix.read() function types that the item to the left of .read() has to be a class, structure, etc. So basically it must have something to do with my constructor at the moment. Except the thing is I don't even know what to put in my constructor, I have a couple functions initiliazed outside of it but otherwise I have just a default constructor. Sorry I know this is really vague but I do NOT understand header files for some ridiculous reason. Any help or input would be great.

Thanks
Mar 21 '07 #3
horace1
1,510 Expert 1GB
Basically it is telling me with the infix.read() function types that the item to the left of .read() has to be a class, structure, etc. So basically it must have something to do with my constructor at the moment. Except the thing is I don't even know what to put in my constructor, I have a couple functions initiliazed outside of it but otherwise I have just a default constructor. Sorry I know this is really vague but I do NOT understand header files for some ridiculous reason. Any help or input would be great.

Thanks
think you are going to have to post some code
Mar 21 '07 #4
Here is my .h so far. As you can see I've just initialized the functions that I"m going to be using in the .cpp.
Expand|Select|Wrap|Line Numbers
  1. namespace Project4a {
  2.  
  3.  
  4.     public ref class Infix : public System::Windows::Forms::Form
  5.     {
  6.     public:
  7.         Infix(void)
  8.         {
  9.             InitializeComponent();            
  10.  
  11.         }
  12.         void initStack(STACK *stack);
  13.         void get_infix(char infix[]);
  14.         void convertToPostfix(char infix[], char postfix[]);
  15.         int isOperator(char c);
  16.         int precedence(char operator1, char operator2);
  17.         int pred_level(char ch);
  18.         void push(STACK *stack, char value);
  19.         char pop(STACK *stack);
  20.         char stackTop(STACK *stack);
  21.         int isEmpty(STACK *stack);
  22.         int isFull(STACK *stack);
  23.         void printResult(char infix[], char postfix[]);
  24.         void print_msg(void);
  25.  
  26.     protected:
  27.  
  28.         ~Infix()
  29.         {
  30.             if (components)
  31.             {
  32.                 delete components;
  33.             }
  34.         }
  35.  
  36.     private:
  37.  
  38.         System::ComponentModel::Container ^components;
  39.  
  40.  
  41.  
However the errors I"m getting are coming up in the assign.cpp which has the following code.
Expand|Select|Wrap|Line Numbers
  1.  
  2. int main()
  3. {
  4.  
  5.    Infix infix;
  6.  
  7.    while (true)
  8.    {
  9.       //cout << "Enter an infix expression like 2*(3+4): " << endl;
  10.  
  11.       infix.read();
  12.  
  13.       if (cin.eof() )
  14.      break;
  15.  
  16.       infix.write();
  17.       cout << " = " << infix.evaluate() << endl;
  18.  
  19.    }  // end while
  20.  
  21.    return 0;
  22. }  // end main
My main question is just about what I need to do in order to get the header file to make it so that the rest of the program recognizes it as an object of a class. Infix that is.

Thanks
Mar 21 '07 #5
Ganon11
3,652 Expert 2GB
Since the class is included inside a namespace, you may have to write

Expand|Select|Wrap|Line Numbers
  1. Project4a::Infix infix;
instead of

Expand|Select|Wrap|Line Numbers
  1. Infix infix;
or at the top of your main() program, put the statement

Expand|Select|Wrap|Line Numbers
  1. using namespace Project4a;
Mar 21 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

22 posts views Thread by Tony Johansson | last post: by
19 posts views Thread by caramel | last post: by
11 posts views Thread by Nhd | last post: by
2 posts views Thread by zeroeight | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.