[Solved] Noobie now knows how to create map :-)

Hey.

I’m trying to create a map like this:

Stomp.h

#include <map>

typedef std::map<String, String> HeaderMap;

Stomp.cpp

#include <Stomp.h>

HeaderMap map;

But as soon as I include my header file I get a bunch of compiler errors. Can anyone help a Noobie out? :smiley:

The errors I get are:

In file included from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_tree.h:61:0,
from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/map:60,
from Stomp.h:34,
from dizplay.cpp:2:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:239:56: error: macro "min" passed 3 arguments, but takes just 2
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:260:56: error: macro "max" passed 3 arguments, but takes just 2
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
In file included from ../inc/application.h:29:0,
from dizplay.cpp:2:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected unqualified-id before 'const'
min(const _Tp& __a, const _Tp& __b)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:193:5: error: expected initializer before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected unqualified-id before 'const'
max(const _Tp& __a, const _Tp& __b)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:216:5: error: expected initializer before 'const'
In file included from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_tree.h:61:0,
from /opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/map:60,
from Stomp.h:34,
from dizplay.cpp:2:
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:239:5: error: 'std::min' declared as an 'inline' variable
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:239:5: error: template declaration of 'const _Tp& std::min'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:242:7: error: expected primary-expression before 'if'
if (__comp(__b, __a))
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:242:7: error: expected '}' before 'if'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:244:7: error: expected unqualified-id before 'return'
return __a;
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:260:5: error: 'max' declared as an 'inline' variable
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:260:5: error: template declaration of 'const _Tp& max'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:263:7: error: expected primary-expression before 'if'
if (__comp(__a, __b))
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:263:7: error: expected '}' before 'if'
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:265:7: error: expected unqualified-id before 'return'
return __a;
^
/opt/gcc_arm/arm-none-eabi/include/c++/4.8.4/bits/stl_algobase.h:266:5: error: expected declaration before '}' token
}
^
make: *** [dizplay.o] Error 1

Is that your complete code, or only part of it? If only partial, would you mind sharing the full code?

Don’t mind at all. Here it is.

Stomp.h

#ifndef STOMPC_H
#define	STOMPC_H

#include <map>
#include "spark_wiring_string.h"

typedef std::map<String, String> HeaderMap;

class Frame {
    String command;
    HeaderMap* headers;
    String body;
    
    public:
        Frame(String command, HeaderMap* headers, String body);
        static Frame unmarshallSingle(String data);
        static Frame * unmarshall(String data);
        String marshall(String command, String body); 
        String toString();
};

Stomp.cpp

#include "Stomp.h"

const int STOMP_EOF = 0;

Frame::Frame(String _command, HeaderMap* _headers, String _body) {
    command = _command;
    headers = _headers;
    body = _body;

    if (command == NULL) {
        //throw std::exception("command must not be null");
    }

    //if (headers == NULL) {
        //throw std::exception("headers must not be null");
    //}

    if (body == NULL) {
        //throw std::exception("body must not be null");
    }
}


String Frame::toString() {
    String out = String(command + "\n");
    out += "\n";
    out += body;
    
    return out;
}

dizplay.ino (with unimportant stuff removed but includes intact)

#include "Stomp.h"
#include "Adafruit_SSD1306/Adafruit_GFX.h"
#include "Adafruit_SSD1306/Adafruit_SSD1306.h"

...... further down in loop
 Frame frame(String("command"), String("body"));
String result = frame.toString()

@michaelkrog: take a look at this post: http://community.spark.io/t/solved-cant-use-vector-or-deque/8242/3 The poster has some of the same errors you are getting. I think they might be related. The OP’s solution is a few posts down.

True.

Changing

#include <map>

to

#undef min
#undef max
#include <map>

…sorted it out

2 Likes

Awesome! I’m glad you got it working!

I tried doing this via the Particle CLI today and I had to add

#undef swap

as well. Not sure if something has changed on the backend, but I thought I’d post that up in case it helps someone.

Hello @michaelkrog,

Did you get your stomp message working?
If so, my I ask you to share your code with me?

Thanks,
Karel.

Just wanted to confirm that I have the same issues with including standard c++ libraries such as map.

In my case:

#include <map>

Resulting error:

/usr/local/gcc-arm-embedded-gcc-arm-none-eabi-4_8-2014q2-20140609-linux-tar-bz2/arm-none-eabi/include/c++/4.8.4/bits/stl_tree.h:735:25: error: macro "swap" requires 2 arguments, but only 1 given
       swap(_Rb_tree& __t);   

I was able to fix the issue with:

#unset swap
1 Like