I am trying to learn some object oriented programming and have written a small program that I copied from a C++ book. The program uses inheritance and defines three types. The base type is INSTRUMENT, this is extended to the two types THERMOMETER and BAROMETER. The types have type bound procedures: INSTRUMENT has SETNO, GETNO, SETLOCATION, GETLOCATION and WRITE. The two meters have SET, GET and WRITE. All this is defined in a module. The main program contains pointers of class INSTRUMENT and variables of type THERMOMETER and BAROMETER, these have the target attribute.
The trouble starts with the pointers. The code looks like this:
pointer => variable ! of type THERMOMETER
CALL pointer % WRITE() ! This works, thermometer data is written, but
CALL pointer % GET(temp) ! does not work. You have to put it in a SELECT TYPE construct. Why?
It seems to me that by using SELECT TYPE one is inquiring about which dynamic type is beeing used. The compiler knows the answer so why does one have to ask? Or, am I misunderstanding all this? If we need to use select type every time we are using a pointer of a base class I think the programming will be very cumbersome. Anyway, we sure need a textbook in Fortran on OOP.
Thanks for any help. Attached is the complete program.