query about pointers used with inheritance

This is about base and derived class objects and pointers. I am wondering if line 5 and 6 in the following code are legal? if your answer is that only line 5 is illegal, can you please explain why line 6 is not?

// d is derived class of class b

b baseObj; // Line 1
d derivedObj; // Line 2
b * pbase; // Line 3
d* pderived; // Line 4
derivedObj = baseObj; //line 5
*pderived = *pbase; //line 6

cheers...
I think you need to re-read and then rewrite your question.
Ok let me ask again. Is any line in the above code illegal?
It depends.

Lines 5 and 6 are illegal unless:
1) 'b' is implicitly convertible to 'd' (has a cast operator), or
2) 'd' contains assignment operator which takes 'b' (value or reference) as an argument.
Topic archived. No new replies allowed.