By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

redifinition error

P: 2
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.
Expand|Select|Wrap|Line Numbers
  1. #ifndef Node_H
  2. #define Node_H
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. //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.
  8.  
  9. class Node{
  10.   private:
  11.     int type_;
  12.     int inter1_;
  13.     int inter2_;
  14.     Node* child1_;
  15.     Node* child2_;
  16.     Node* parent_;
  17.  
  18.   public:
  19.  
  20.     Node(Node* n1, Node* n2, int t);
  21.  
  22.     int getInter1(){
  23.     return inter1_;
  24.     }
  25.     int getInter2(){
  26.         return inter2_;
  27.     }
  28.     void setInter1(int i){
  29.     inter1_=i;
  30.     }
  31.     void setInter2(int i){
  32.     inter2_=i;
  33.     }
  34.     int getType(){
  35.       return type_;
  36.     }
  37.  
  38.     Node* getChild1(){
  39.       return child1_;
  40.     }
  41.  
  42.     Node* getChild2(){
  43.       return child2_;
  44.     }
  45.  
  46.     Node* getParent(){
  47.       return parent_;
  48.     }
  49.  
  50.     void setType(int i){
  51.       type_=i;
  52.     }
  53.  
  54.     void setChild1(Node* n){
  55.       child1_=n;
  56.     }
  57.  
  58.     void setChild2(Node* n){
  59.       child2_=n;
  60.     }
  61.  
  62.     void setParent(Node* n){
  63.       parent_=n;
  64.     }
  65.  
  66.     void printNode(){
  67.       cout << "type: " << getType()<<endl;  
  68.     }
  69. };
  70. #endif
Sep 22 '10 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
There is no error in the code you are posting.
Sep 22 '10 #2

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

Post your reply

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