Skip to main content
Improved constructor.
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126

In this class declaration:

class Test
{
public :
    Test();
    ~Test();
    Map<int, String> *list = new Map<int, String>();
};

This line is wrong:

    Map<int, String> *list = new Map<int, String>();

You can't execute procedural code when declaring a class. That has to go into the constructor or some other function.

For example, this compiles without errors:

Test.h

#ifndef _Test_h
#define _Test_h


#include "Arduino.h"
#include "Map.h"

class Test
{
public :
    Test() { list = new Map<int, String>();String>; } ;
    ~Test();
    Map<int, String> *list;
};

#endif

In this class declaration:

class Test
{
public :
    Test();
    ~Test();
    Map<int, String> *list = new Map<int, String>();
};

This line is wrong:

    Map<int, String> *list = new Map<int, String>();

You can't execute procedural code when declaring a class. That has to go into the constructor or some other function.

For example, this compiles without errors:

Test.h

#ifndef _Test_h
#define _Test_h


#include "Arduino.h"
#include "Map.h"

class Test
{
public :
    Test() { list = new Map<int, String>(); } ;
    ~Test();
    Map<int, String> *list;
};

#endif

In this class declaration:

class Test
{
public :
    Test();
    ~Test();
    Map<int, String> *list = new Map<int, String>();
};

This line is wrong:

    Map<int, String> *list = new Map<int, String>();

You can't execute procedural code when declaring a class. That has to go into the constructor or some other function.

For example, this compiles without errors:

Test.h

#ifndef _Test_h
#define _Test_h


#include "Arduino.h"
#include "Map.h"

class Test
{
public :
    Test() { list = new Map<int, String>; } ;
    ~Test();
    Map<int, String> *list;
};

#endif
Added example code.
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126

In this class declaration:

class Test
{
public :
    Test();
    ~Test();
    Map<int, String> *list = new Map<int, String>();
};

This line is wrong:

    Map<int, String> *list = new Map<int, String>();

You can't execute procedural code when declaring a class. That has to go into the constructor or some other function.

For example, this compiles without errors:

Test.h

#ifndef _Test_h
#define _Test_h


#include "Arduino.h"
#include "Map.h"

class Test
{
public :
    Test() { list = new Map<int, String>(); } ;
    ~Test();
    Map<int, String> *list;
};

#endif

In this class declaration:

class Test
{
public :
    Test();
    ~Test();
    Map<int, String> *list = new Map<int, String>();
};

This line is wrong:

    Map<int, String> *list = new Map<int, String>();

You can't execute procedural code when declaring a class. That has to go into the constructor or some other function.

In this class declaration:

class Test
{
public :
    Test();
    ~Test();
    Map<int, String> *list = new Map<int, String>();
};

This line is wrong:

    Map<int, String> *list = new Map<int, String>();

You can't execute procedural code when declaring a class. That has to go into the constructor or some other function.

For example, this compiles without errors:

Test.h

#ifndef _Test_h
#define _Test_h


#include "Arduino.h"
#include "Map.h"

class Test
{
public :
    Test() { list = new Map<int, String>(); } ;
    ~Test();
    Map<int, String> *list;
};

#endif
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126

In this class declaration:

class Test
{
public :
    Test();
    ~Test();
    Map<int, String> *list = new Map<int, String>();
};

This line is wrong:

    Map<int, String> *list = new Map<int, String>();

You can't execute procedural code when declaring a class. That has to go into the constructor or some other function.