Problem Multiple definition of enum

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • puneetsardana88
    New Member
    • Aug 2009
    • 57

    Problem Multiple definition of enum

    Hi

    I was implementing BFS and DFS

    So I have three class stack,queue,nod e and main class

    I have put Node class in Node.h

    Code:
    #define SIZE_NEIGHBOURS 10
    #define SIZE_GRAPH 100
    #include<iostream>
    enum STATUS{ready=0,waiting=1,processed=2};
    class Node
     {
         public:
         char info;
         int distance;
          STATUS node_status;
         Node *adjacent[SIZE_NEIGHBOURS];
         Node *next;
         Node()
         {
            // cout<<"Hui";
             info=0;
             distance=0;
             next=NULL;
             node_status=ready;
             for(int i=0;i<SIZE_NEIGHBOURS;i++)
                adjacent[i]=NULL;
         }
     };
    I #include"node.h " in both stack and queue headers..

    Now when I #include"stack. h" and #include"queue. h" I got an error multiple definition of enuf status. I know the reason that it is defined twice

    1) node of stack
    2) node of queue
    Whats the possible solution to avoid this???Please help...
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Your names are colliding with standard names, please try renaming your class names to something a bit different and try again.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      You include files should use multiple include protection mechanisms, the most ubiquitous being use of preprocessor symbols like this

      Code:
      #ifndef NODE_H_INCLUDED
      #define NODE_H_INCLUDED
      
      // Declarations and definitions of node.h
      
      #endif
      This will stop the declarations in node.h being processed more than once which is what the problem is.

      Comment

      • puneetsardana88
        New Member
        • Aug 2009
        • 57

        #4
        @Redson

        It worked earlier with same names

        @banfa

        I copy pasted the code(of yours) it still gave same error...Now what i did

        Code:
        #ifndef SIZE_GRAPH
        #define SIZE_NEIGHBOURS 10
        #define SIZE_GRAPH 100
        #include<iostream>
        enum STATUS{ready=0,waiting=1,processed=2};
        class Node
         {
             public:
             char info;
             int distance;
              STATUS node_status;
             Node *adjacent[SIZE_NEIGHBOURS];
             Node *next;
             Node()
             {
                // cout<<"Hui";
                 info=0;
                 distance=0;
                 next=NULL;
                 node_status=ready;
                 for(int i=0;i<SIZE_NEIGHBOURS;i++)
                    adjacent[i]=NULL;
             }
         };
        #endif
        It worked....Can you please tell me what you were saying?Hope I ll learn something...And thanks for your help

        Comment

        • puneetsardana88
          New Member
          • Aug 2009
          • 57

          #5
          got the answer

          it should be

          #ifndef NODE_H
          #define NODE_H

          Many Thanks to all

          Comment

          Working...