I’ve been looking into using the following code in my app, but while it will compile ok in an external C++ compiler (codeblocks/gcc) I get an error when using it in the web IDE,
#include <array>
#include <map>
using namespace std;
int selector=D0;
int red=A2;
int green=A1;
int yellow=A0;
map<int,array<int,3>> pinmap; -- [[take this as line 16]]
pinmap[red]={{OUTPUT,DIGITAL,LOW}};
pinmap[green]={{OUTPUT,DIGITAL,LOW}};
pinmap[yellow]={{OUTPUT,DIGITAL,LOW}};
pinmap[selector]={{INPUT_PULLDOWN,false,false}};
This compiles fine in codeblocks (when I wrap that last block in " int main(){} ")
but as part of the code in the .ino file created on the web IDE I get an error;
switch_play.cpp:16:1: error: reference to 'map' is ambiguous
int yellow=A0;
Is this down to quirks of the IDE env. I’m not sure of?
You are trying to use std::map (which is great) but Arduino compatibility has a #define'ed map macro that could be interfering.
I am not sure what you mean by wrapping the last block in int main(){} since you will not be able to replace main in the web IDE. Maybe that is just for testing in the other compiler?
You should be able to put this code into a .cpp file in the web IDE by clicking the little circle plus in the upper right to add new .h and .cpp files and then pasting it in. If it does not work, try #undef map as a work-around.
Ok, I can understand the conflict now if the name ‘map’ is defined elsewhere. - and yes, the int main(){} - that’s referring to ; this code will compile successfully if I put it in int main(){ … code …} in a plain C++ / GCC compiler IDE (I am using codeblocks as a separate IDE)
#undef map
gives the same error though - reference to map is ambiguous - on the line referring to map.
I tried std::map, this appears to resolve the ambiguity, though I then get the error
17: pinmap does not name a type - though I’m guessing thats a c++ error on my part, nothing to do with the web IDE/Environment
Edit: //yep, that one was my bad
Note that you need an extra space when closing a template that contains another template specification. Did that make sense? It is an old problem within C++ since shift right has precedence.
Just remember that if your template contains a template then >> has to be > >
Your other compiler might be C++ x11 compliant, which handles this correctly, I believe.