Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Pls I am getting the following error messages and I haven't been able to fix the problem:

1. error c2662: 'Function::Evaluate ' cannot convert 'this' pointer to 'const Function to Fumction &,

2.Error C2663 'Function::GetReference' 2 overloads have no legal conversion for 'this' pointer.

3.Error C2248: :CObject::operator=' cannot access private member declared in Class 'CObject'.
This diagnostic occurred in compilet generated function 'CList<type> &CList<type>::operator = (const CList<type> &)'.
It appears the volume of code IS posted is scarimg people away
So I decided to romove the code.
Posted
Updated 20-May-14 10:05am
v5
Comments
[no name] 20-May-14 8:54am    
And what would you like us to do with this? The error messages mean exactly what they say.
Gbenbam 20-May-14 12:57pm    
Do you mind looking at the code added?
CPallini 20-May-14 8:55am    
You should post the offending code.
Gbenbam 20-May-14 12:59pm    
I have posted a segment of the code here?
OriginalGriff 20-May-14 8:59am    
Those aren't debugging problems: they are compilation errors. You debug running programs, not compiler output...

As for the cause, we can't tell. Remember that we can't see your screen, access your HDD, or read your mind, so we have no idea what lines of code the error messages are related to. So either show us the lines of code and tell us which error goes with which line, or double click on the error and it will probably take you to the line directly.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

1. The method Function::Evaluate() is declared as const, but the implementation of the function either tries to modify a member of the instance, or calls a member function that is not const.

Solution: Check what element(s) in the function implementation are non-const and either change the implementation to only use const members, or, if you really mean to change values, remove the const qualifier from the function signature.

2. The compiler found two overloads for the function Function::GetReference(), but neither function signature matches how it is used

Solution: since the error mentions the 'this' pointer, it may just be a subsequent error of 1 - i. e. the reason that the compiler couldn't match one of the overloads may be that 'this' in the current is const, but none of the function overloads is a const function. If that is not the case, check the line of code that the error message refers to and make sure that the way you call the function matches the signature of the function that you mean to call.

3. While the error message itself is clear, the code the message points to may not provide an immediate hint where the problem lies, as it may be in code that is not your own: it seems that you defined a list of objects of type CObject. The class list itself declares an assignment operator which copies the contents of the list, and therefore needs to access the assignment operator of it's elements, in this case CObject::operator=(). Since that member function was declared private (or protected), the CList implementation cannot access it, resulting in the error message.

Solution: I'm not sure if the class CObject you're using is one you defined yourself, or one provided by a framework such as MFC. I assume it's the latter. In this case, defining a list of elements of type CObject doesn't make any sense! What you meant to do is define a list of elements that are of some (unknown) type derived from CObject. If that assumption is accurate, the correct thing to do is define a list of elements of type pointer to CObject instead.

P.S.: all these answers and solutions can be derived from just looking at the error messages and understanding their meaning. Looking the error codes up on MSDN helps, too. That said, it would be easier to give more accurate advice if you had simply posted the lines of code that these error messages point to!
 
Share this answer
 
Comments
Gbenbam 20-May-14 12:54pm    
Perhaps you will like to take a look at the updated question again.
Gbenbam 20-May-14 13:13pm    
The code lines generating the first two errors are obvious.The last error line's genetator line is some line CObject.
Gbenbam 20-May-14 13:17pm    
I don't know if I am right buy I think the last error stems from the fact that CObject has problem with processing a CList of FunctionToken object.
Gbenbam 21-May-14 2:24am    
Your solution did it for me!I looked closely at the error messsges and the associated line code

.At your suggestion I examined Function::Evaluate again.The problem was that in solving the CList generated error I changed one of its constructor to ta k e a pointer instead of a reference.That's was was why some other code that needed to use the function complained about I. ability to convert a this pointer to a reference.Well, the error that was responsible for the other error was thag the List template class that inherits CList did not define an assignment function, so the attempt by the assignment operator to call its assignment operator failed.The idea to write an assignment operator for it came from your solution.The fact that the non-availability of an assignment opetator for the class was the problem was made obvious when the error message changed to a complain that the assignment operator for the operator must return a valure(apparently I had written just 'this' instead of 'return *this' .That return error helped in generating an error that let the cat out of the bag so to say.So thanks so much for your solution it saved me from a lot of stress and sleepless night.Once again , thanks a lot.
Stefan_Lang 21-May-14 2:39am    
On a sidenote, I saw you derived List from another class, CList. When you derive a class, you should always provide constructors and assignment operators for your derived class. You did the former but not the latter. In this case, it would work anyway, but if you had provided the operator the error message would have pointed to your code rather than that of CList::operator=()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900