invalid conversion from 'const ... ' to '...'

Hi everyone,

I keep getting errors from the following code:
1
2
3
4
5
6
7
8
9
10
         int orgCount, newCount;
         wordcount *wrdPtr;
         wrd = words.find(*wrd);//error: invalid conversion from 'const wordcount*' to 'wordcount*'

         orgCount = &wrdPtr.getCount;//error: request for member 'getCount' in 'wrdPtr', which is of non-class type 'wordcount*'
         newCount = orgCount + 1; 
         words.erase(*wrd);

         wordcount *exwrd = new wordcount(tempWord, newCount);
         words.insert(*exwrd);

I am trying to get the address by calling words.find(*wrd), then get the count number of that object from the address.
wordcound is the class name.

here is my getCount():
1
2
3
4
    const int getCount() const
    {
      return count;
    }


and find(), which can not be changed in any ways:
1
2
3
4
5
6
7
8
9
      const dataType* find(const dataType &findData) const 
      {
         // this function looks for findData in the tree.
	     // If it finds the data it will return the address of the data 
	     // in the tree. otherwise it will return NULL
	     
         if (root == NULL) return NULL;
         else return root->find(findData);
      }


Thanks for the help.
1st error: Your find function returns constant pointer. You cannot assign const pointer to non-const one.

2nd error: you are trying to call method of address of pointer (pointer to pointer). Maybe you wanted wrdPtr->getCount()?
Do you have any suggestions of how I can fix this?
I need to get the address from find function, then use that address to get the count number.

Thanks for your help.
find function already returns address to found element.
I suggest to do something like
1
2
3
const wordcount *wrdPtr;
wrdPtr = words.find(/*What to find*/);
orgCount = wrdPtr->getCount();
Last edited on
Thanks for the advice, but now I get:
1
2
3
4
5
6
wordcount *wrdPtr;
wrdPtr = words.find(*wrd);
// error: invalid conversion from 'const wordcount*' to 'wordcount*'
orgCount = wrdPtr->getCount;
//error: argument of type 'int (wordcount::)()' does not match 'int'
Last edited on
I have missed const in my example. Fixed now.
3rd line. Answer, how the function is called? What is the difference between mine and yours line?
Last edited on
Look at line 1 of MiiNiPaa's example and line 1 of your example
Oh... my bad.

Thanks for the help guys!!!
Much appreciated.
Topic archived. No new replies allowed.