Creating a child class of UTFT

Hello everybody,

In the following simple program, I display "Hello" :

#include <UTFT.h>
#include <avr/pgmspace.h>

extern uint8_t SmallFont[];

UTFT myGLCD(ITDB32S, 38, 39, 40, 41);

void setup() {
  myGLCD.InitLCD(PORTRAIT);
  myGLCD.setFont(SmallFont);
  myGLCD.fillScr(255, 255, 255);
  myGLCD.setColor(255, 255, 255);
  myGLCD.print("Hello", 10, 10);
}

void loop() {
}

It works fine.

Now, I would like to add a method to the UTFT class. For this I create a child class

#include <UTFT.h>
#include <avr/pgmspace.h>

extern uint8_t SmallFont[];

class UTFT_M : public UTFT {
public:
  UTFT_M(byte model, int RS, int WR,int CS, int RST, int SER=0);
};

UTFT_M::UTFT_M(byte model, int RS, int WR,int CS, int RST, int SER) {
  UTFT(model, RS, WR, CS, RST, SER);
}

UTFT_M myGLCD(ITDB32S, 38, 39, 40, 41); 

void setup() {
  myGLCD.InitLCD(PORTRAIT);
  myGLCD.setFont(SmallFont);
  myGLCD.fillScr(255, 255, 255);
  myGLCD.setColor(255, 255, 255);
  myGLCD.print("Hello", 10, 10);
}

void loop() {
}

This program compiles but displays nothing. So what is wrong ?

I am sorry, I am a beginner in C++.

Sincerely.

Pierre

No need to apologise Pierre. Your question is vastly superior to many..
I think the problem lies in the way you call the constructor of UTFT.

I note that you call it like this:

UTFT_M::UTFT_M(byte model, int RS, int WR,int CS, int RST, int SER) {
  UTFT(model, RS, WR, CS, RST, SER);
}

I've some code that makes use of wxWidgets, using wxFormBuilder as the tool to create the windows and the required classes.
In one project, I've an 'About Box', whose class is called wxTestFrameAbout. This class inherits from aboutDialog, which in turn
inherits from wxDialog.

Here's the definition of the aboutDialog class:

///////////////////////////////////////////////////////////////////////////////
/// Class aboutDialog
///////////////////////////////////////////////////////////////////////////////
class aboutDialog : public wxDialog
{
	private:

	protected:
		wxStaticText* m_staticText2;
		wxStaticText* m_staticText3;
	public:
		aboutDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("About Char Designer"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 279,178 ), long style = wxDEFAULT_DIALOG_STYLE );
		~aboutDialog();
};

And the definition of wxTestFrameAbout

class wxTestFrameAbout : public aboutDialog
{
	public:
        wxTestFrameAbout(wxWindow *parent);
        ~wxTestFrameAbout() {};
        void setVersionString(wxString newStr);
};

Note the addition of the member function setVersionString (so the correct string is returned for different platforms i.e msWindows, linux, 32bit, 64bit)
Looking at the (automatically generated) body of the constructor for wxTestFrameAbout, we see the following:

wxTestFrameAbout::wxTestFrameAbout(wxWindow *parent) : aboutDialog(parent)
{

}

Which is where the difference lies. Notice the way the constructor for aboutDialog is invoked?
In your code, you call the base-class constructor inside the constructor for the child-class. In the above code, it follows the function's signature, leaving the body empty.

So, change your code to this, would be my suggestion:

UTFT_M::UTFT_M(byte model, int RS, int WR,int CS, int RST, int SER) : UTFT(model, RS, WR, CS, RST, SER)
{
  
}

Thank you "enhzflep", that works very well.

Coming from the pascal, I had not seen this subtlety of writing.

Sincerely.

Pierre

A pleasure Pierre. Thanks for making me rethink mods to the tft library - infinitely smarter to inherit from it than change it, as I did. Another task for later tonight.

[playful taunt mode: on]

ChPr:
Coming from the pascal

That's okay, I won't hold that against you! :stuck_out_tongue: :stuck_out_tongue: (me too, actually. TurboPascal_6_0 := 'fun'; :blush:)

[playful taunt mode: off]

Simon.

enhzflep:
... (me too, actually. TurboPascal_6_0 := 'fun'; :blush:) ...

For me, it is DELPHI 6 for Windows and Lazarus 1.0 for Windows and Linux (Ubuntu)

Pierre

Ah! Lazarus eh?

I tried that a few years back, but was always disappointed with the size of the smallest, trivial GUI "Hello World" program I could create with it.
Around that time I came across Code::Blocks and MinGW, rediscovering gcc/g++ too, haven't looked back.

I wonder if carpenters get excited when they remember one of the first hammers they owned!?