While I have a lot of embedded C experience I'm not a C++ guru by any means but I've spent the past few days doing some research into this problem I'm having, learning about classes, inheritance and polymorphism. I think I understand how everything should work, so I'm at a loss as to why things aren't working!
I'm currently trying to write a custom implementation of HardwareSerial for a piece of custom hardware I'm working on. Right now I have a completely minimal stripped down version of the class hierarchy and I cannot get the basic functionality to run. The processor crashes in almost every scenario (not sure where it is stuck but it appears to be halted probably in a default error handler).
The Print class, unedited from Arduino, defined the 'write' function as pure virtual, so I define it in the child class (HardwareSerial) but the processor crashes as soon as 'write' is called from the Print class. I can however successfully call it directly using Serial.write('!').
If I make 'write' not be pure virtual and define a default function in the base class (Print), the processor crashes in the exact same way (even if 'write' is completely removed from the child class).
It only succeeds if I don't declare 'write' as virtual at all (in which case the default version I created in the base class gets called.)
It compiles and links without any errors (arm gcc) and the normal Arduino core (plus a multitiude of other cores I looked at for reference) all seem to work, so what am I missing?