c++ - g++ 在 ‘(’ token 之前预期不合格 ID

标签 c++ g++

我在使用 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: error: expected unqualified-id before ‘(’ token

我不确定为什么会收到此错误,我搜索了很多并发现了一些“类似”的问题,但我无法解决我的问题。

编辑:所以这是错误日志:

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 个 header (STL_vector 和 STL_bvector)给我完全相同的错误,其余的没问题。有什么想法吗?

预先感谢您的帮助。

最佳答案

这可能是由于预处理器损坏了您的代码,可能是因为您有宏 max定义。 C 库可能会发生这种情况,因为通常 C 标准允许 C 标准库函数实际上是宏(尽管我只在 MSVC 上看到过这样的事故)。

要检查,你可以

  • 使用 gcc -E 预处理源代码并在输出中搜索相应的代码。检查它是否完好。
  • 添加 #undef max #include <vector> 之前的行看看是否有帮助。

关于c++ - g++ 在 ‘(’ token 之前预期不合格 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7641167/

相关文章:

c++ - 如何处理 Windows 上 .pro 文件中不同的库名称?

C++ 检测操作系统版本

c++ - 我如何确保 "<<"运算符适用于模板化 ADT 定义中的任何泛型类型?

c++ - 缩短作为模板参数传递到 CRTP ("pass me"中的长模板派生类)

c++ - 使用 g++ 将多个源文件编译成一个 .o

c++ - SDL 2 程序使用 1.4 GB 内存?

c++ - g++-4.8 C++ stdlib 动态库

C++ - 类方法函数指针的 unordered_map 的初始化列表

c++ - 以下内联汇编有什么问题?

c++ - Mac 终端编译错误