I am using Arduino 1.8.5 ide. I am just creating a class with two typename which name is "Map". This class takes all int and String variations. Like;
class Map<int, int>;
class Map<int, String>;
class Map<String, int>;
class Map<String, String>;
Map<int, String> *list = new Map<int, String>();
If I create instance of this class like above in Main.ino file then everything is ok. But if I create it another file with .h extension which is "Test.h" then compilation fails. These are files;
Main.ino
#include "Map.h"
#include "Test.h"
Test *test = new Test();
Map<int, String> *list = new Map<int, String>();
void setup() {
}
void loop() {
}
Map.cpp
#include "Arduino.h"
#include "Map.h"
template<typename E, typename T> Map<E, T>::Map()
{
}
template class Map<int, int>;
template class Map<int, String>;
template class Map<String, int>;
template class Map<String, String>;
Map.h
#ifndef Map_h
#define Map_h
#include "Arduino.h"
template<typename E, typename T> class Map {
public:
Map();
~Map();
};
#endif
Test.h
#ifndef _Test_h
#define _Test_h
#include "Arduino.h"
#include "Map.h"
class Test
{
public :
Test();
~Test();
Map<int, String> *list = new Map<int, String>();
};
#endif
Error is;
In file included from C:\Users\zafer\Desktop\Main\Main.ino:3:0:
Test.h:14: error: expected ';' at end of member declaration
Map<int, String> *list = new Map<int, String>();
^
Test.h:14: error: expected unqualified-id before '>' token
Map<int, String> *list = new Map<int, String>();
^
Test.h:14: error: wrong number of template arguments (1, should be 2)
Map<int, String> *list = new Map<int, String>();
^
In file included from C:\Users\zafer\Desktop\Main\Main.ino:2:0:
Map.h:6: error: provided for 'template<class E, class T> class Map'
template<typename E, typename T> class Map {
^
exit status 1
expected ';' at end of member declaration
Sorry, If it's been already resolved and I couldn't find it.
Thank you.