[Resolved] Class creation problem

30 Jan 2010 . Edited: 30 Jan 2010

Hello,

This is a very basic C++ question but cannot find the problem. I am trying to create a class for a 4x20 serial LCD display. When compiling I get "Object of abstract class LCD20X4 is not allowed (E322) whern using it this way :

main.cpp :

  • #include "mbed.h"
  • #include "SerialLCD.h"
  • LCD20X4 mylcd(p28, p27);

 

SerialLCD.h :

  • #include "mbed.h"
  • class LCD20X4 : public Stream {
  • public :
  • LCD20X4(PinName tx, PinName rx);
  • protected :
  • Serial _cmd;
  • };

SerialLCD.cpp

 

  • #include "mbed.h"
  • #include "SerialLCD.h"
  • LCD20X4 :: LCD20X4(PinName tx, PinName rx) : _cmd(tx, rx) { // Constructor
  • wait_ms(1000);
  • }

If I remove "public Stream", it compiles and runs. But I want to use Stream to have printf function available. I tried to do as the TextLCD class without much success. I am sure it is a basic inheritance stuff I did not get right.

Thanks in davance.

30 Jan 2010

That error normally means that you have an undefined virtual function in the base class.

Looking at Stream.h at http://mbed.org/projects/libraries/svn/mbed/trunk/Stream.h

it looks like you will need to define the protected functions _putc() and _getc() in your LCD20X4 class to get it to work.

Hope that helps.

Richard.

30 Jan 2010

Thanks,

I have to check that.

I tryed to do an inheritance of Serial rather than Stream. I have a different error message at compilation. It says there is : No Default Constructor for class "mbed::Serial"

30 Jan 2010

Ok, I got it, syntax problem ;-)

Thanks again

31 Jan 2010

No problem, glad you got it sorted :-).

Richard.