473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
2 6141
Banfa
9,065 Expert Mod 8TB
You have a ; at the end of line 8
Sep 24 '10 #2
Aha, thank-you!
Sep 27 '10 #3

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

Similar topics

5
by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1,...
30
by: Joost Ronkes Agerbeek | last post by:
Why is it allowed in C++ to call a static member function of an object through an instance of that object? Is it just convenience? tia, Joost Ronkes Agerbeek
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
8
by: SJ | last post by:
Hi: I have a class which has a static member function. The function implements something common to all instances. How can the static member function know all of the (Get access to the instances'...
5
by: Martin Vorbrodt | last post by:
so if i have this: // header.h class X { public: static int s = 1; }; i still need this:
7
by: Uwe Grawert | last post by:
Hello, a C-function expects me to give a pointer to a function as parameter. i want to give this function a pointer to a member function of a class but the compiler gives me an error: void...
11
by: Marco Wedekind | last post by:
Hello all, I have a strange compiler behaviour with this code: ---- Begin of code snippet ---- class Base { public: static unsigned int ClassId();
10
by: Simon | last post by:
Hi, I have something like // // common.h const unsigned long m_dwStyle = 0x123; // // common.h
3
by: silentcoast | last post by:
Alright im not sure why but im getting a "member function redeclaration not allowed" error when I to compile this simple program. main.cpp #include "main.h" CNetwork net; int main() {...
10
by: blangela | last post by:
If I pass a base class object by reference (likely does not make a difference here that it is passed by reference) as a parameter to a derived class member function, the member function is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.