473,804 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Member function redeclaration not allowed

2 New Member
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 6172
Banfa
9,065 Recognized Expert Moderator Expert
You have a ; at the end of line 8
Sep 24 '10 #2
addison5390
2 New Member
Aha, thank-you!
Sep 27 '10 #3

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

Similar topics

5
9380
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, 2, func);
30
3502
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
3640
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 support. (first i compiled them with g++3.x. ERR means compiler will bark, otherwise it does accept it. Then the Comeau C/C++ 4.3.3 comes)
8
1838
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' handles) instances? Thanks in advance for any help
5
4289
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
4378
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 (MyClass::*)(void*, void*) can not be converted to void (*)(void*, void*) i declared the function as protected. Is it not possible to give
11
11059
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
21363
by: Simon | last post by:
Hi, I have something like // // common.h const unsigned long m_dwStyle = 0x123; // // common.h
3
13482
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() { int on = 0;
10
4121
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 allowed to access the protected data members of the base object. This surprises me. Can someone explain why this is? I suspect there is a good reason and I am just having a slow day to not come up with it myself. Bob
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9169
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.