Go Down

Topic: Class constructor not executing (Read 366 times) previous topic - next topic

blt

Hi hope this is not a silly question
In the following code the class constructor does not appear to do anything.
I expect to see on the graphics display attached to my Mega 1280 "Hello foo" followed, after a few seconds, by "Hello bar"
I do not see "Hello foo"  but I do see "Hello bar"

can anyone help please

Code: [Select]
//TR6

#include "TR6Display.h"
#include "ks0108.h"   
#include "Arial14.h"     

TR6Display TR6_Display();

void setup()
{
        delay(2000);
        GLCD.Init(NON_INVERTED);
GLCD.ClearScreen();
        delay(2000);
        GLCD.SelectFont(Arial_14);
        GLCD.GotoXY(20, 2);
        GLCD.Puts("Hello bar");

}

void loop()
{
}



Code: [Select]
//TR6Display.h


#ifndef TR6Display_h
#define TR6Display_h

class TR6Display
{
public:
TR6Display();
};

#endif



Code: [Select]
//TR6Display.cpp

#include "Wprogram.h"
#include "TR6Display.h"
#include "ks0108.h"
#include "Arial14.h"

TR6Display::TR6Display()
{
        delay(2000);
        GLCD.Init(NON_INVERTED);
       GLCD.ClearScreen();
        delay(2000);
        GLCD.SelectFont(Arial_14);
        GLCD.GotoXY(20, 2);
        GLCD.Puts("Hello foo");

}

crimony

Some information here.

Short answer, "Don't do that". You can't rely on any of the hardware being setup properly before constructors for global objects are called. Rework your class with a begin() or init() member function that does the initialisation, and call it in setup().

blt

Thanks for your reply crimony - I'll take your advice

blt

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview