Hi,I spent all night trying to figure this out. Could someone take a look and show me what I'm missing? I getting this compiler error: unterminated #ifndef . But I have ifndef at the beginning and endif at the end of the class.

//Header file. 
//Class definition for teh stack ADT

#ifndef _mystack_H
#include <ostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define _mystack_H


const unsigned int maxSize = 10;

class Stack
{
      public:
                Stack(); //constructor
      
                ~Stack(); //Destructor

                bool isEmptyStack();
                
                bool isFullStack();
                
                void pushStack(int newItem);
                
                void popStack(int item);
                
                void initializeStack();
                
                void fillStack(int numSize);
                
                void exchangeTopAndBottom(Stack &stk);
                
                void printStack(Stack &stk);
                
                int sumStack(Stack &stk);
                
                void OddElem(Stack &stk);
                
                //void commonStack(Stack &stk1, Stack &stk2);
                
                void intersectStack(Stack &stk1, Stack &stk2);

       private:
                int maxSize;  //variable to store the maximum stack size
                int stackTop; //variable to poit to the top of the stack
                Stack arrList;//pointer to the array that holds the stack 
                              //elements
        
};      

#endif

Hi,I spent all night trying to figure this out. Could someone take a look and show me what I'm missing? I getting this compiler error: unterminated #ifndef . But I have ifndef at the beginning and endif at the end of the class.

//Header file. 
//Class definition for teh stack ADT

#ifndef _mystack_H
#include <ostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define _mystack_H


const unsigned int maxSize = 10;

class Stack
{
      public:
                Stack(); //constructor
      
                ~Stack(); //Destructor

                bool isEmptyStack();
                
                bool isFullStack();
                
                void pushStack(int newItem);
                
                void popStack(int item);
                
                void initializeStack();
                
                void fillStack(int numSize);
                
                void exchangeTopAndBottom(Stack &stk);
                
                void printStack(Stack &stk);
                
                int sumStack(Stack &stk);
                
                void OddElem(Stack &stk);
                
                //void commonStack(Stack &stk1, Stack &stk2);
                
                void intersectStack(Stack &stk1, Stack &stk2);

       private:
                int maxSize;  //variable to store the maximum stack size
                int stackTop; //variable to poit to the top of the stack
                Stack arrList;//pointer to the array that holds the stack 
                              //elements
        
};      

#endif

First of all, "Stack arrList" --this is not legal as far as I know in C++. This should be Stack* arrlist. Fix this first and try it.

I'm not sure about your #ifndef problem. I copy/pasted your code and it compiled after I fixed the Stack*. My guess is that it's one of your overlapping includes that's not being properly handled by your particular compiler.

fstream automatically includes ostream. Here's a map of how that works:
http://www.cplusplus.com/reference/iostream/
Anything that an arrow points to, will automatically include its parent class, tracing backwards. So you only need to include fstream. First remove #include <ostream> and try to compile. Pretty sure stdio automatically includes stdlib, too. You should try to remove one or the other. Stdio is C input output. In my opinion you shouldn't use both the C++ streams library and the Stdio library, as they both perform similar tasks.

You should #include as few things as possible. Not only does it bloat your code, but it can confuse your compiler as well.

Edited 5 Years Ago by Greywolf333: n/a

You need to format your defines as such:
#ifndef
#define

#endif

after you said #ifndef _mystack_H
you need to then put a #define right after that on line 5

It worked! I repositioned the ifndef, define, and endif. Then I changed #include <ostream> to #include <iostream> and I compiled the code on a different compiler, and it worked. I fixed the Stack *arrList too.

Now I'm getting another error. The last one I hope. It says

[Linker error] undefined reference to `Stack::Stack()'

And there is a linker error displayed for all the functions in my implementation file. Also, #include "mystack.h" has been highlighted in both the main and implementation file. Please help me with this one too.
Thanks.

This question has already been answered. Start a new discussion instead.