朋友 class 指向不同命名空间中同名的 class

the friend class point to a class of the same name in a different namespace

很抱歉,我无法将问题描述清楚。 编译器给出的错误是:

D:\download\tensorflow-master\tensorflow-master\tensorflow\contrib\cmake\build\protobuf\src\protobuf\src\google/protobuf/arena.h(883): error C3855: “Eigen::Map”: type parameter 'MapOption' is incompatible with the declaration
D:\download\tensorflow-master\tensorflow-master\tensorflow\contrib\cmake\build\protobuf\src\protobuf\src\google/protobuf/arena.h(883): error C2976: “Eigen::Map”: too few type arguments

错误来自tensorflow官方代码,我可以运行用C++编写的示例程序。当我尝试将我的 tensorflow 代码插入我的另一个项目时,出现了错误。

 template <typename Key, typename T>
 friend class Map;

我知道问题是 'Map' 指向 Eigen::Map 而它需要指向 google::protobuff::Map。此外,'Map' 的声明位于 google::protobuff 命名空间下。 以前有人遇到过同样的问题吗? 我尽力给出一个明确的声明。非常感谢!

这就是为什么你不应该:

  1. 在声明范围内使用 using namespace

  2. 依赖标准或公共库中保留或使用的标识符的重新定义

两者都会导致名称冲突,后者可能会导致无法检测到的冲突。