I'm getting this error when using stl_vector.h
. I'm on Linux using g++ to compile.
{
if (max_size() - size() < __n)
__throw_length_error(__N(__s));
const size_type __len = size() + std::max(size(), __n); //THE ERROR IS ON THIS LINE!
return (__len < size() || __len > max_size()) ? max_size() : __len;
}
usr/include/c++/4.5/bits/stl_vector.h:1143:40: error: expected unqualified-id before
‘(’
token
I'm not sure why I'm getting this error, I have searched a lot and found some "similar" problems but I can't solve mine.
EDIT: so here's the error log:
In file included from /usr/include/c++/4.5/vector:65:0,
from ../../RL_Toolbox/include/caction.h:34,
from ../../RL_Toolbox/include/cagent.h:35,
from shortestpathQLearning.cpp:42:
/usr/include/c++/4.5/bits/stl_vector.h:1143:40: error: expected unqualified-id before ‘(’ token
You can see in the previous error log that "vector" gets called by the header "caction.h" like this:
//THESE ARE THE INCLUDES IN "caction.h"
#ifndef CACTION_H
#define CACTION_H
#include <stdio.h>
#include <vector> //HERE IT CALLS <vector>
#include <list>
#include <map>
#include "cbaseobjects.h"
then Vector calls bits/stl_vector.h like this:
#ifndef _GLIBCXX_VECTOR
#define _GLIBCXX_VECTOR 1
#pragma GCC system_header
#include <bits/stl_algobase.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_vector.h>//HERE IT CALLS stl_vector.h
#include <bits/stl_bvector.h> //Im actually getting the exact same error from stl_vector.h on this header
just the last 2 headers from vector (stl_vector and stl_bvector) give me the exact same error, the rest are ok. Any ideas?
Thanks in advance for your help.
The expected unqualified id error shows up due to mistakes in the syntax. As there can be various situations for syntax errors, you'll need to carefully check your code to correct them. Also, this post points toward some common mistakes that lead to the same error.
In C, an identifier is expected in the following situations: in a list of parameters in an old-style function header. after the reserved words struct or union when the braces are not present, and. as the name of a member in a structure or union (except for bit fields of width 0).
This may be caused by the preprocessor damaging your code, probably because you have macro max
defined. This can happen with the C library, because generally the C standard allows C standard library functions to be actually macros (although I've only seen such a mishap on MSVC).
To check, you can
gcc -E
and search the output for the corresponding code. Check if it is undamaged.#undef max
line before #include <vector>
and see if it helps.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With