Hi everybody :-)
I'm hoping someone can explicitly explain to me how casting works. I understand the theory: "conversion of an object of one type to be of another type, as long as the conversion makes sense." However, as a practicality I'm not sure how this works. For example, take the following code extract:
Animal Bear ("Yogi", 5); // creates a new object of type animal
ofstream fout (YogiFile, ios::binary); // create new ofstream object for editing Yogifile in Binary code
fout.write ((char*) &Bear, sizeof Bear); // write Bear object to YogiFile
The book I'm learning from doesn't explain this so well - it states that the read() and write() functions are expecting a char pointer as the first parameter and so we must cast the address of the object to be a char pointer. So far so good. However it doesn't go into the details of how this is possible - I don't understand how you can convert the address of a user-created object to be a char pointer - I would've thought the two would surely be incompatable.
Whilst I understand the basic of how to implement casting, I really need to know how it works before I can move on. Any help would be much appreciated!! Cheers :-)