Problem matching Function Signitures with const

Hello Experts,

I have what shold be a fairly easy 500 pts for someone.  I just cant seem to get my function signitures to match correctly in a Tree class that I am making.

My problem is this;

I have a public member function:                

                           int leafcount() const;                      <---  this must be the signiture because it is a requirement of the teacher.

in the function body I place a call to this funciton private member function:

                           void leafcount(const TreeNode*&, int&) const;  

And when I compile I get these errors:

                           BTree.cpp:                  In member function `int BTree::leafcount() const':
                           BTree.cpp:184:            no matching function for call to `BTree::leafcount(TreeNode*const&, int&) const'
                           BTree.cpp:182:            candidates are: int BTree::leafcount() const
                           BTree.h:47:                 void BTree::leafcount(const TreeNode*&, int&) const
                           BTree.cpp:                   In member function `void BTree::leafcount(const TreeNode*&, int&) const':
                           BTree.cpp:                   193: no matching function for call to `BTree::leafcount(TreeNode*const&, int&) const'
                           BTree.cpp:182:             candidates are: int BTree::leafcount() const
                           BTree.cpp:189:             void BTree::leafcount(const TreeNode*&, int&) const
                           BTree.cpp:195:             no matching function for call to `BTree::leafcount(TreeNode*const&, int&) const'
                           BTree.cpp:182:             candidates are: int BTree::leafcount() const
                           BTree.cpp:189:             void BTree::leafcount(const TreeNode*&, int&) const

Now, I can fix all my problems if I simply change my function calls...

                           int leafcount() const;     &     void leafcount(const TreeNode*&, int&) const;  


                            int leafcount()             &      void leafcount(TreeNode*&, int&);

but as I said, I need the const...  So thats it!.. To help you help me, below is my BTree class header file and the implementation of both functions.


//BTree.h fiel

#include <cstdlib>
#include "TreeNode.h"

using namespace std;

#ifndef BTREE_H
#define BTREE_H

class BTree
      //int findkey(const int& key) const;//
      //int findmax(const int& key) const;//

      BTree(const BTree& atree);
      bool insert(const int& d);
      int findheight();
      void RecursiveInOrder(void(*visit)(int& i));
                void NonRecursivePostOrder(void (*visit)(int& i));
      void NonRecursiveLevelOrder(void(*visit)(int& i));
      int nodecount() const;
      int leafcount() const;            
      int countfullnodes();


                //void leafcout(const TreeNode*&, int&);//
      TreeNode *root;
      bool insert(TreeNode*&, const int&);
      bool copyTree(TreeNode* treePtr, TreeNode*& newTreePtr);
      int findheight(TreeNode*);
      void RecursiveInOrder(TreeNode*, void(*visit)(int& i));
      void leafcount(const TreeNode*&, int&) const;
      int totalnodes;
      void countfullnodes(TreeNode*&, int&);




//Implementation of functions:

int BTree::leafcount() const
      int count = 0;
      leafcount(root, count);
      return count;

void BTree::leafcount(const TreeNode*& parent, int& count) const
            if(parent->left != NULL)
                  leafcount(parent->left, count);
            if(parent->right != NULL)
                  leafcount(parent->right, count);
                  count = count + 1;



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


> void leafcount(const TreeNode*&, int&) const;  

you wanted to pass reference to a const pointer to the function.
this is not necessary. chnage it to simply pass the pointer.

void leafcount(const TreeNode *, int &) const;

that's all. the way you're calling it is correct.

if you want to do it in more elegant way, (but still as recursive function,)
don't pass int & for count, but return the count as the result of the function:

unsigned leafcount(const TreeNode *node) const
    if (node == 0) return 0;
    return 1 + leafcount(node->left) + leafcount(node->right);

have fun,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
travishabermanAuthor Commented:
Thank you much George!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.