Member function redeclaration not allowed

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

    Member function redeclaration not allowed

    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

    Code:
    #pragma once
    #ifndef TREENODE_H
    #define TREENODE_H
    #include <iostream>
    #include <string>
    class TreeNode{
    private:
    std::string word;
    int count;
    TreeNode *left;
    TreeNode *right;
    
    TreeNode() {}
    
    public:
    	TreeNode(std::string word, int count, TreeNode *left, TreeNode *right);
    	void downtree(std::string s);
    	void printTree();
    
    
    };
    #endif
    Here is the .cpp file

    Code:
    #include <stdafx.h>
    #include "TreeNode.h"
    #include <iostream>
    using namespace std;
    
    
    
    TreeNode::TreeNode(std::string word, int count, TreeNode *left, TreeNode *right);
    {
    	downtree(word);
    }
    void TreeNode::downtree(std::string s){	
    	if (word.compare(s)  > 0 ){
    		if (left == NULL) {
    
    		left = new TreeNode;
    		left->word = s;
    		left->count = 1;
    		left->left = NULL;
    		left->right = NULL;
    		}
    		else	
    		{left.downtree(s);
    		}
    	}
    	else if (word.compare(s)  < 0 ){
    		if (right == NULL) {
    
    		right = new TreeNode;
    		right->word = s;
    		right->count = 1;
    		right->left = NULL;
    		right->right = NULL;
    		}
    		else{
    		right.downtree(s);
    		}
    	}
    	else if (word.compare(s)  == 0 ){
    		count++;
    	}
    }

    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!
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You have a ; at the end of line 8

    Comment

    • addison5390
      New Member
      • Sep 2010
      • 2

      #3
      Aha, thank-you!

      Comment

      Working...