Thx again
JLBorges for your explanation and links. Let me give you a clearer
illustration of my problem. I have a base class that is basically the encapsulation of a linked list; let's call this class A. I have two different
classes derived from A, let's call them class B and class C. I have read data
from an input file into an object, say b, of class B using a user-defined, non-class function. However the data processing I want to do is on an object, say c, of class C. So, I want to copy the contents of b into c using an assignment statement; like this,
c = b;
I know there is the option of writing a new non-class function to read the input data directly into object c; but, I do not want to do that. That's the backdrop to my OP.
I have tried to overload the assignment operator in derived class C by including the function prototype
const C& operator=(const B&);
in class C's definition.
As expected, the corresponding function definition goes like this:
1 2 3 4 5 6 7 8 9
|
const C& C::operator=(const B& otherList)
{
.
.
if (this != &otherList) //compiler error
.
.
}
|
I encountered the compiler error above which reads:
comparison between distinct pointer types 'C*' and 'B*' lacks a cast.
This compiler error was one of the problems I ran into. I do understand why the compiler flagged the statement as erroneous. Is there a way to circumvent this?