This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problems with c++ classes

Hello,

first of all I would like you to know a little bit about the project I'm doing (can't tell much:).

I am building a system in which I'd like to have a menu implemented as some kind of a finite state machine.

The menu should be able to be nested.

I would like the code for it to be very simple, something like this:

MENU menu;

MENU m1(&menu);
MENU m2(&menu);

MENU m11(&m1);
MENU m21(&m2);
MENU m22(&m2);
MENU m23(&m2);

This code should give me the menu that is nested and looks like this:

MENU---
|      |
M1     M2---
|      |    |
M11    M21  M22

I made a C++ code that works in Visual Studio 2010, but when I tried to migrate it to Keil uVision and put it on a microcontroller, it compiles well, but it blocks before entering the main().

I read that it is generally not a good idea to use dynamic memory allocation in embedded systems, and I don't really need dynamic allocation of memory for the menu, since it will be static, and defined at compiling.

But I would really like to use class approach to it.

To give you another example: i implemented button matrix as a class, so it can easily be defined this way:

        ButtonNetwork BN;

        BN.AddOutLine(LPC_GPIO0, 26);
        BN.AddOutLine(LPC_GPIO0, 25);
        BN.AddOutLine(LPC_GPIO0, 24);

        BN.AddInputLine(LPC_GPIO3, 26);
        BN.AddInputLine(LPC_GPIO3, 25);
        BN.AddInputLine(LPC_GPIO1, 18);
        BN.AddInputLine(LPC_GPIO1, 19);

This way I can define a button matrix very easy with 3 output lines, and 4 input lines.

Also the same problem - the number of lines will be static. I just prefer this approach, because it is easier for later changes to a software.

The microcontroller I use is LPC1768 Cortex M3.
Please tell me what is the easiest way to make it work.

As a temporary solution, I tried increasing the heap size but it doesn't help.

Ill wait for your answers before continuing with this,
Thanks for even reading.

0