redifinition error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ThomasKA
    New Member
    • Sep 2010
    • 2

    redifinition error

    I get the following error:
    Node.h:9: error: redefinition of 'class Node'
    Node.h:8: error: previous definition of 'class Node'

    When I compile my program. I cannot understand why it pops up since I have used hedder guards.
    Code:
    #ifndef Node_H
    #define Node_H
    
    #include <iostream>
    using namespace std;
    
    //class node has four fields: type, child1, child2 and parent. The type is -1 if it is a inner node, 0 if it is the root and a positive number (cooresponding to the item it represent) if it is a leaf. The leaves functions eighter returns or changes it fields.
    
    class Node{
      private:
        int type_;
        int inter1_;
    	int inter2_;
    	Node* child1_;
        Node* child2_;
        Node* parent_;
    
      public:
    
    	Node(Node* n1, Node* n2, int t);
    
    	int getInter1(){
    	return inter1_;
    	}
    	int getInter2(){
    		return inter2_;
    	}
    	void setInter1(int i){
    	inter1_=i;
    	}
    	void setInter2(int i){
    	inter2_=i;
    	}
    	int getType(){
          return type_;
        }
    
        Node* getChild1(){
          return child1_;
        }
    
        Node* getChild2(){
          return child2_;
        }
    
        Node* getParent(){
          return parent_;
        }
        
    	void setType(int i){
          type_=i;
        }
        
    	void setChild1(Node* n){
          child1_=n;
        }
    
        void setChild2(Node* n){
          child2_=n;
        }
    
        void setParent(Node* n){
          parent_=n;
        }
        
    	void printNode(){
          cout << "type: " << getType()<<endl;  
        }
    };
    #endif
    Last edited by Banfa; Sep 22 '10, 01:14 PM. Reason: Added [code] ... [/code] tags round the code.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    There is no error in the code you are posting.

    Comment

    • ThomasKA
      New Member
      • Sep 2010
      • 2

      #3
      I found the error. I had an old hidden headerfile. Don't know how it got there but now it's gone

      Comment

      Working...