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

Member function redeclaration not allowed

P: 2
So, below is code for a binary tree, the structure is referred to as TreeNode. I'm having some trouble separating what information goes into the TreeNode.h file and the TreeNode.cpp file.

Here is the .h file

Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2. #ifndef TREENODE_H
  3. #define TREENODE_H
  4. #include <iostream>
  5. #include <string>
  6. class TreeNode{
  7. private:
  8. std::string word;
  9. int count;
  10. TreeNode *left;
  11. TreeNode *right;
  12.  
  13. TreeNode() {}
  14.  
  15. public:
  16.     TreeNode(std::string word, int count, TreeNode *left, TreeNode *right);
  17.     void downtree(std::string s);
  18.     void printTree();
  19.  
  20.  
  21. };
  22. #endif
  23.  
  24.  
Here is the .cpp file

Expand|Select|Wrap|Line Numbers
  1. #include <stdafx.h>
  2. #include "TreeNode.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. TreeNode::TreeNode(std::string word, int count, TreeNode *left, TreeNode *right);
  9. {
  10.     downtree(word);
  11. }
  12. void TreeNode::downtree(std::string s){    
  13.     if (word.compare(s)  > 0 ){
  14.         if (left == NULL) {
  15.  
  16.         left = new TreeNode;
  17.         left->word = s;
  18.         left->count = 1;
  19.         left->left = NULL;
  20.         left->right = NULL;
  21.         }
  22.         else    
  23.         {left.downtree(s);
  24.         }
  25.     }
  26.     else if (word.compare(s)  < 0 ){
  27.         if (right == NULL) {
  28.  
  29.         right = new TreeNode;
  30.         right->word = s;
  31.         right->count = 1;
  32.         right->left = NULL;
  33.         right->right = NULL;
  34.         }
  35.         else{
  36.         right.downtree(s);
  37.         }
  38.     }
  39.     else if (word.compare(s)  == 0 ){
  40.         count++;
  41.     }
  42. }
  43.  
  44.  

The intent of this tree is to be able to take in a string and place it in the proper position.

The error messages:
Error 5 error C2761: '{ctor}' : member function redeclaration not allowed
Error 6 error C2447: '{' : missing function header (old-style formal list?)
Error 7 error C2228: left of '.downtree' must have class/struct/union
Error 8 error C2228: left of '.downtree' must have class/struct/union

Does anyone know the source of these error messages? I need a second pair of eyes on this. Thanks!
Sep 24 '10 #1
Share this Question
Share on Google+
2 Replies


Banfa
Expert Mod 5K+
P: 8,916
You have a ; at the end of line 8
Sep 24 '10 #2

P: 2
Aha, thank-you!
Sep 27 '10 #3

Post your reply

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