【发布时间】:2011-10-03 22:02:21
【问题描述】:
我在使用stl_vector.h 时遇到此错误。我在 Linux 上使用 g++ 编译。
{
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: 错误:
‘(’令牌之前的预期 unqualified-id
我不知道为什么会出现这个错误,我搜索了很多并发现了一些“类似”的问题,但我无法解决我的问题。
编辑:这是错误日志:
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
您可以在前面的错误日志中看到“vector”被标题“caction.h”调用,如下所示:
//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"
然后 Vector 像这样调用 bits/stl_vector.h:
#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
只有来自 vector 的最后 2 个标头(stl_vector 和 stl_bvector)给了我完全相同的错误,其余的都可以。有什么想法吗?
提前感谢您的帮助。
【问题讨论】:
-
你在某个地方碰巧有
#define max或类似的东西吗? -
您是直接包含
stl_vector.h还是包含vector标头 -
你能在预处理器完成工作后查看文件吗?这可能会揭示问题。
-
只使用
<vector>有什么问题吗?stl_vector.h应该是一个甚至不能保证存在的实现细节。 -
@Dabbler:这不是他的代码。它在 bits/stl_vector.h,
size_type _M_check_len()的正文中。