Does anyone know how to read an object out of a binary file in a polymorphic way? My psuedo code is a follows:

class baseClass

class derivedClassA

class derivedClassB

decide on which derived class to use

baseClass = new derivedClassA


baseClass = new derivedClassB

Write baseClass to binary file

Read baseClass from binary file

Do stuff based on whether baseClass was writen as derivedClassA or derivedClassB