c++ - 包含 <algorithm> 时的命名空间 "manufacturing"

标签 c++ namespaces g++

<分区>

我有一个命名空间问题,这让我发疯。这里有一个名为“Utility”的命名空间,由另一位程序员编写,我在我的一些代码中使用了它。一个文件只会给我带来问题。这个文件包括<算法>,我必须拥有它。我已经尝试了各种重新排列和其他随机的东西来尝试摆脱它。我一辈子都弄不明白为什么 STL_algo.h 有这个问题。

/usr/include/c++/4.6/bits/stl_algo.h: In function ‘void std::random_shuffle(_RAIter, _RAIter)’:
/usr/include/c++/4.6/bits/stl_algo.h:5152:40: error: ‘std::Utility’ has not been declared

最佳答案

我可以reproduce the exact error, line numbers, positions and all , 与

#include <cstdlib>
#define rand Utility::rand
#include <algorithm>

产生

In file included from /usr/local/gcc-4.6.4/lib/gcc/x86_64-unknown-linux-gnu/4.6.4/../../../../include/c++/4.6.4/algorithm:63:0,
                 from prog.cc:3:
/usr/local/gcc-4.6.4/lib/gcc/x86_64-unknown-linux-gnu/4.6.4/../../../../include/c++/4.6.4/bits/stl_algo.h: In function 'void std::random_shuffle(_RAIter, _RAIter)':
/usr/local/gcc-4.6.4/lib/gcc/x86_64-unknown-linux-gnu/4.6.4/../../../../include/c++/4.6.4/bits/stl_algo.h:5152:40: error: 'std::Utility' has not been declared

因此,通过您的 header 并寻找 #define'ing rand 的东西。狠狠地揍这个骇人听闻的黑客的负责人,然后删除 #define

关于c++ - 包含 <algorithm> 时的命名空间 "manufacturing",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29954491/

相关文章:

c++ - 为什么 std::shared_ptr<T> = std::unique_ptr<T[]> 编译,而 std::shared_ptr<T[]> = std::unique_ptr<T[]> 不编译?

c++ - 使用 gcc 的 -fno-math-errno 可能产生哪些副作用?

c++ - 数组反转

c++ - 指向 vector 的指针不指向

c++ - 相同的 C++ 代码导致 Windows 上的无限循环和 OSX 上的预期行为

c++ - 使用两个着色器程序打开两个不同的三角形

r - 切换和 tabsetPanel 的 Shiny 命名空间问题

c++ - boost 计时器在 "for"循环中产生相同的结果?

ruby-on-rails - Rails - 如何在 View 中引用命名空间表属性

c++ - 带有命名空间的编译器的有趣行为