user34193: I am doing a display class using 2*8 lcd on an arduino to display and navigate my menu using MenuBackend library but i can make instance of these variables. I tried using static variable it did not work either. 
here is the codes 
GPSMenu.h : 
#ifndef GPSMENU_h
#define GPSMENU_h
#include "Arduino.h"
#include <MenuBackend.h>
#include <LiquidCrystal.h>

class GPSMenu
{
public:
GPSMenu(LiquidCrystal* lcd);

  void navigateMenus( byte read);

  private:
  void menuChangeEvent(MenuChangeEvent changed);
  void menuUseEvent(MenuUseEvent used);
  void menuSetup();
  LiquidCrystal *_lcd;

  MenuBackend menu =  MenuBackend(menuUseEvent,menuChangeEvent);

  //beneath is the list of menu items needed to build the menu
  MenuItem Battery     = MenuItem(menu, "Battery ", 1);//----usable
  MenuItem Iteneraire  = MenuItem(menu, "Itener  ", 1);
  MenuItem Start       = MenuItem(menu, "Start   ", 2);//----usable
  MenuItem Stop        = MenuItem(menu, "Stop    ", 2);//----usable
  MenuItem FileOpn     = MenuItem(menu, "FileOpn ", 2);
  MenuItem NewFile     = MenuItem(menu, "NewFile ", 3);//----usable
  MenuItem OverWr      = MenuItem(menu, "OverWr  ", 3);//----usable
  MenuItem PtOpn       = MenuItem(menu, "PtOpn   ", 2);
  MenuItem Seconde_1   = MenuItem(menu, "Court   ", 3);//----usable
  MenuItem Secondes_15 = MenuItem(menu, "Moyen   ", 3);//----usable
  MenuItem Minute_1    = MenuItem(menu, "Long    ", 3);//----usable
  MenuItem GPSData     = MenuItem(menu, "GPSData ", 1);
  MenuItem Coord       = MenuItem(menu, "Coord   ", 2);//----usable
  MenuItem Time        = MenuItem(menu, "Time    ", 2);//----usable
  MenuItem Status      = MenuItem(menu, "Status  ", 2);//----usable
  MenuItem SpdAlti     = MenuItem(menu, "SpdAlti ", 2);//----usable
  MenuItem Filemnger   = MenuItem(menu, "Filemngr", 1);//----usable

};
#endif

GPSMenu.cpp:
#include "Arduino.h"
#include <MenuBackend.h>    //MenuBackend library - copyright by Alexander Brevig
#include <LiquidCrystal.h>  //this library is included in the Arduino IDE
#include "GPSMenu.h"  //this library is included in the Arduino IDE

GPSMenu::GPSMenu(LiquidCrystal* lcd){
 _lcd = lcd;
 _lcd->begin(8, 2);
 _lcd->clear();
  GPSMenu::menuSetup();

}

//this function builds the menu and connects the correct items together
void GPSMenu::menuSetup()
{
  //add the file menu to the menu root
  menu.getRoot().add(Battery);
  Battery.addRight(Iteneraire).addRight(GPSData ).addRight(Filemnger);
  Iteneraire.add(Start ).addRight(Stop).addRight(FileOpn).addRight(PtOpn);
  GPSData.add(Coord).addRight(Time).addRight(Status).addRight(SpdAlti);
  FileOpn.add(NewFile).addRight(OverWr);
  PtOpn.add(Seconde_1).addRight(Secondes_15).addRight(Minute_1);
}

//  This is where you define a behaviour for a menu item

void GPSMenu::menuUseEvent(MenuUseEvent used)
 {
   _lcd->setCursor(0, 0);
   _lcd->print(used.item.getName());
   _lcd->setCursor(0, 1);
   _lcd->print("Used    ");
}
/*
  Here we get a notification whenever the user changes the menu
  That is, when the menu is navigated
*/
void GPSMenu::menuChangeEvent(MenuChangeEvent changed)
{
  _lcd->setCursor(0, 0);
  _lcd->print(changed.from.getName());
  _lcd->setCursor(0, 1);
  _lcd->print(changed.to.getName());
}

void GPSMenu::navigateMenus( byte read) {
  MenuItem currentMenu=menu.getCurrent();

  switch (read){

  case 1:

    if(!(currentMenu.hasAfterChildren())){  //if the current menu has a child and has been pressed enter then menu navigate to item below
      menu.use();
    }
    else{  //otherwise, if menu has no child and has been pressed enter the current menu is used
      menu.moveDown();
    }
    break;

  case 2:
    menu.moveLeft();

    break;
  case 3:
    menu.moveRight();

    break;
  case 4:
    menu.moveUp();
    break;
  }
}

And the errors on my terminal : 
In file included from GPSMenu.cpp:4:0:
GPSMenu.h:20:46: error: ‘void GPSMenu::menuUseEvent(MenuUseEvent)’ cannot appear in a constant-expression
       static MenuBackend menu =  MenuBackend(menuUseEvent,menuChangeEvent);
                                              ^
GPSMenu.h:20:59: error: ‘void GPSMenu::menuChangeEvent(MenuChangeEvent)’ cannot appear in a constant-expression
       static MenuBackend menu =  MenuBackend(menuUseEvent,menuChangeEvent);
                                                           ^
GPSMenu.h:20:74: error: invalid in-class initialization of static data member of non-integral type ‘MenuBackend’
       static MenuBackend menu =  MenuBackend(menuUseEvent,menuChangeEvent);
                                                                          ^
GPSMenu.h:20:74: error: initializer invalid for static member with constructor
GPSMenu.h:20:74: note: (an out of class initialization is required)
GPSMenu.h:23:46: error: ‘GPSMenu::menu’ cannot appear in a constant-expression
       static MenuItem Battery     = MenuItem(menu, "Battery ", 1);//----usable
                                              ^
GPSMenu.h:23:65: error: invalid in-class initialization of static data member of non-integral type ‘MenuItem’
       static MenuItem Battery     = MenuItem(menu, "Battery ", 1);//----usable
                                                                 ^
GPSMenu.h:23:65: error: initializer invalid for static member with constructor
GPSMenu.h:24:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Iteneraire  = MenuItem(menu, "Itener  ", 1);
                                                          ^
GPSMenu.h:25:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Start       = MenuItem(menu, "Start   ", 2);//----usable
                                                          ^
GPSMenu.h:26:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Stop        = MenuItem(menu, "Stop    ", 2);//----usable
                                                          ^
GPSMenu.h:27:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem FileOpn     = MenuItem(menu, "FileOpn ", 2);
                                                          ^
GPSMenu.h:28:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem NewFile     = MenuItem(menu, "NewFile ", 3);//----usable
                                                          ^
GPSMenu.h:29:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem OverWr      = MenuItem(menu, "OverWr  ", 3);//----usable
                                                          ^
GPSMenu.h:30:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem PtOpn       = MenuItem(menu, "PtOpn   ", 2);
                                                          ^
GPSMenu.h:31:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Seconde_1   = MenuItem(menu, "Court   ", 3);//----usable
                                                          ^
GPSMenu.h:32:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Secondes_15 = MenuItem(menu, "Moyen   ", 3);//----usable
                                                          ^
GPSMenu.h:33:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Minute_1    = MenuItem(menu, "Long    ", 3);//----usable
                                                          ^
GPSMenu.h:34:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem GPSData     = MenuItem(menu, "GPSData ", 1);
                                                          ^
GPSMenu.h:35:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Coord       = MenuItem(menu, "Coord   ", 2);//----usable
                                                          ^
GPSMenu.h:36:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Time        = MenuItem(menu, "Time    ", 2);//----usable
                                                          ^
GPSMenu.h:37:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Status      = MenuItem(menu, "Status  ", 2);//----usable
                                                          ^
GPSMenu.h:38:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem SpdAlti     = MenuItem(menu, "SpdAlti ", 2);//----usable
                                                          ^
GPSMenu.h:39:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Filemnger   = MenuItem(menu, "Filemngr", 1);//----usable


user10394: You can't set the value of a variable in the header file (class definition).
class foo
{
  int a = 1;  // This doesn't work
};

This works
class foo2
{
  static int b;
};
int foo2::b = 2;


34193: <p>I am doing a display class using 2*8 lcd on an arduino to display and navigate my menu using MenuBackend library but i can make instance of these variables. I tried using static variable it did not work either. </p>

<p><strong>here is the codes</strong> </p>

<p>GPSMenu.h : </p>

<pre><code>#ifndef GPSMENU_h
#define GPSMENU_h
#include "Arduino.h"
#include &lt;MenuBackend.h&gt;
#include &lt;LiquidCrystal.h&gt;

class GPSMenu
{
public:
GPSMenu(LiquidCrystal* lcd);

  void navigateMenus( byte read);

  private:
  void menuChangeEvent(MenuChangeEvent changed);
  void menuUseEvent(MenuUseEvent used);
  void menuSetup();
  LiquidCrystal *_lcd;

  MenuBackend menu =  MenuBackend(menuUseEvent,menuChangeEvent);

  //beneath is the list of menu items needed to build the menu
  MenuItem Battery     = MenuItem(menu, "Battery ", 1);//----usable
  MenuItem Iteneraire  = MenuItem(menu, "Itener  ", 1);
  MenuItem Start       = MenuItem(menu, "Start   ", 2);//----usable
  MenuItem Stop        = MenuItem(menu, "Stop    ", 2);//----usable
  MenuItem FileOpn     = MenuItem(menu, "FileOpn ", 2);
  MenuItem NewFile     = MenuItem(menu, "NewFile ", 3);//----usable
  MenuItem OverWr      = MenuItem(menu, "OverWr  ", 3);//----usable
  MenuItem PtOpn       = MenuItem(menu, "PtOpn   ", 2);
  MenuItem Seconde_1   = MenuItem(menu, "Court   ", 3);//----usable
  MenuItem Secondes_15 = MenuItem(menu, "Moyen   ", 3);//----usable
  MenuItem Minute_1    = MenuItem(menu, "Long    ", 3);//----usable
  MenuItem GPSData     = MenuItem(menu, "GPSData ", 1);
  MenuItem Coord       = MenuItem(menu, "Coord   ", 2);//----usable
  MenuItem Time        = MenuItem(menu, "Time    ", 2);//----usable
  MenuItem Status      = MenuItem(menu, "Status  ", 2);//----usable
  MenuItem SpdAlti     = MenuItem(menu, "SpdAlti ", 2);//----usable
  MenuItem Filemnger   = MenuItem(menu, "Filemngr", 1);//----usable
</code></pre>

<p>};</p>

<pre><code>#endif
</code></pre>

<p>GPSMenu.cpp:</p>

<pre><code>#include "Arduino.h"
#include &lt;MenuBackend.h&gt;    //MenuBackend library - copyright by Alexander Brevig
#include &lt;LiquidCrystal.h&gt;  //this library is included in the Arduino IDE
#include "GPSMenu.h"  //this library is included in the Arduino IDE

GPSMenu::GPSMenu(LiquidCrystal* lcd){
 _lcd = lcd;
 _lcd-&gt;begin(8, 2);
 _lcd-&gt;clear();
  GPSMenu::menuSetup();

}

//this function builds the menu and connects the correct items together
void GPSMenu::menuSetup()
{
  //add the file menu to the menu root
  menu.getRoot().add(Battery);
  Battery.addRight(Iteneraire).addRight(GPSData ).addRight(Filemnger);
  Iteneraire.add(Start ).addRight(Stop).addRight(FileOpn).addRight(PtOpn);
  GPSData.add(Coord).addRight(Time).addRight(Status).addRight(SpdAlti);
  FileOpn.add(NewFile).addRight(OverWr);
  PtOpn.add(Seconde_1).addRight(Secondes_15).addRight(Minute_1);
}

//  This is where you define a behaviour for a menu item

void GPSMenu::menuUseEvent(MenuUseEvent used)
 {
   _lcd-&gt;setCursor(0, 0);
   _lcd-&gt;print(used.item.getName());
   _lcd-&gt;setCursor(0, 1);
   _lcd-&gt;print("Used    ");
}
/*
  Here we get a notification whenever the user changes the menu
  That is, when the menu is navigated
*/
void GPSMenu::menuChangeEvent(MenuChangeEvent changed)
{
  _lcd-&gt;setCursor(0, 0);
  _lcd-&gt;print(changed.from.getName());
  _lcd-&gt;setCursor(0, 1);
  _lcd-&gt;print(changed.to.getName());
}

void GPSMenu::navigateMenus( byte read) {
  MenuItem currentMenu=menu.getCurrent();

  switch (read){

  case 1:

    if(!(currentMenu.hasAfterChildren())){  //if the current menu has a child and has been pressed enter then menu navigate to item below
      menu.use();
    }
    else{  //otherwise, if menu has no child and has been pressed enter the current menu is used
      menu.moveDown();
    }
    break;

  case 2:
    menu.moveLeft();

    break;
  case 3:
    menu.moveRight();

    break;
  case 4:
    menu.moveUp();
    break;
  }
}
</code></pre>

<p>And the errors on my terminal : </p>

<pre><code>In file included from GPSMenu.cpp:4:0:
GPSMenu.h:20:46: error: ‘void GPSMenu::menuUseEvent(MenuUseEvent)’ cannot appear in a constant-expression
       static MenuBackend menu =  MenuBackend(menuUseEvent,menuChangeEvent);
                                              ^
GPSMenu.h:20:59: error: ‘void GPSMenu::menuChangeEvent(MenuChangeEvent)’ cannot appear in a constant-expression
       static MenuBackend menu =  MenuBackend(menuUseEvent,menuChangeEvent);
                                                           ^
GPSMenu.h:20:74: error: invalid in-class initialization of static data member of non-integral type ‘MenuBackend’
       static MenuBackend menu =  MenuBackend(menuUseEvent,menuChangeEvent);
                                                                          ^
GPSMenu.h:20:74: error: initializer invalid for static member with constructor
GPSMenu.h:20:74: note: (an out of class initialization is required)
GPSMenu.h:23:46: error: ‘GPSMenu::menu’ cannot appear in a constant-expression
       static MenuItem Battery     = MenuItem(menu, "Battery ", 1);//----usable
                                              ^
GPSMenu.h:23:65: error: invalid in-class initialization of static data member of non-integral type ‘MenuItem’
       static MenuItem Battery     = MenuItem(menu, "Battery ", 1);//----usable
                                                                 ^
GPSMenu.h:23:65: error: initializer invalid for static member with constructor
GPSMenu.h:24:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Iteneraire  = MenuItem(menu, "Itener  ", 1);
                                                          ^
GPSMenu.h:25:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Start       = MenuItem(menu, "Start   ", 2);//----usable
                                                          ^
GPSMenu.h:26:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Stop        = MenuItem(menu, "Stop    ", 2);//----usable
                                                          ^
GPSMenu.h:27:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem FileOpn     = MenuItem(menu, "FileOpn ", 2);
                                                          ^
GPSMenu.h:28:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem NewFile     = MenuItem(menu, "NewFile ", 3);//----usable
                                                          ^
GPSMenu.h:29:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem OverWr      = MenuItem(menu, "OverWr  ", 3);//----usable
                                                          ^
GPSMenu.h:30:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem PtOpn       = MenuItem(menu, "PtOpn   ", 2);
                                                          ^
GPSMenu.h:31:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Seconde_1   = MenuItem(menu, "Court   ", 3);//----usable
                                                          ^
GPSMenu.h:32:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Secondes_15 = MenuItem(menu, "Moyen   ", 3);//----usable
                                                          ^
GPSMenu.h:33:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Minute_1    = MenuItem(menu, "Long    ", 3);//----usable
                                                          ^
GPSMenu.h:34:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem GPSData     = MenuItem(menu, "GPSData ", 1);
                                                          ^
GPSMenu.h:35:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Coord       = MenuItem(menu, "Coord   ", 2);//----usable
                                                          ^
GPSMenu.h:36:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Time        = MenuItem(menu, "Time    ", 2);//----usable
                                                          ^
GPSMenu.h:37:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Status      = MenuItem(menu, "Status  ", 2);//----usable
                                                          ^
GPSMenu.h:38:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem SpdAlti     = MenuItem(menu, "SpdAlti ", 2);//----usable
                                                          ^
GPSMenu.h:39:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
       MenuItem Filemnger   = MenuItem(menu, "Filemngr", 1);//----usable
</code></pre>
 10394: <p>You can't set the value of a variable in the header file (class definition).</p>

<pre><code>class foo
{
  int a = 1;  // This doesn't work
};
</code></pre>

<p>This works</p>

<pre><code>class foo2
{
  static int b;
};
int foo2::b = 2;
</code></pre>
