Expected unqualified-id before '(' token caused by #include <vector>

I was trying to write a very simple function to read ADC 20 times, remove min and max and find the average. I stored the readings in a std::vector arr, but this error keeps showing up

../wiring/inc/spark_wiring_arduino_constants.h:111:18: expected unqualified-id before '(' token

I realized even only include the "vector" library and not do anything else would still give the same error.

Here's my code. I commented out the function that has vectors in it. But even this is giving me error.

#include "ADS1015_async.h"
#include "application.h"
#include "MCP4728.h"
#include "math.h"
#undef swap
#include "vector"
//using namespace std;
//std::vector<int> arr;

Once I comment out

#include "vector"

everything compiles.

Have you tried this?

#include <vector>

Yes I tried both.

The error is pointing to an include file from the system. ScruffR posted a bug report on this error here:

If this is the same error regarding the max macro, then try undefining that macro prior to including the header for vector.

Hi Thanks for the reply. But I didn’t use the max macro in the code. I didn’t define anything in my code actually.

You don’t have to have used it. The standard library contains a definition of max (and min) that would conflict with one in the constants header. Just including the vector header could cause a clash.

I’m not sure if this is definitely the problem, but based on ScruffR’s bug report you should look into it carefully. Try:

#undef max
#include <vector>

Note that there may be other conflicts to deal with such as min.

ohhhh It did compile thank you so much!!

Has there been any progress on fixing this issue? I’m trying to switch a project using lists to vectors and the provided fix isn’t working for me.