【问题标题】:the friend class point to a class of the same name in a different namespace友元类指向不同命名空间中的同名类
【发布时间】:2018-05-31 05:57:01
【问题描述】:

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

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;

我知道问题是“地图”指向 Eigen::Map 而它需要指向 google::protobuff::Map。此外,“地图”的声明位于 google::protobuff 命名空间下。 有没有人遇到过同样的问题? 我正在尽力给出明确的声明。非常感谢!

【问题讨论】:

  • 我们无法告诉您任何信息,请用英文填写您的错误,并提供minimal reproducible example
  • 猜猜你的头文件或 cpp 文件中是否有 using namespace Eigen 在你的一个包含之前?
  • 然后使用完全限定名称,Eigen::Mapgoogle::protobuff::Map 并忘记 using namespace 构造

标签: c++ tensorflow eigen3


【解决方案1】:

这就是为什么你不应该:

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

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

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

【讨论】:

  • 感谢您的回答!我通过删除“使用命名空间”解决了这个问题。但是因为opencv和tensorflow的宏冲突又出现了新的问题,请问这个问题怎么解决(官方代码不允许修改)
  • @BLACK 取决于冲突的类型。如果这是枚举和宏之间的冲突,那么标题的顺序可能会有所帮助。如果具有相同名称和不同内容的宏定义冲突..我想,这就是使用单独编译单元的原因
  • 独立于原因,那是一个单独的问题,需要一个新的问题,新的minimal reproducible example
猜你喜欢
  • 2017-05-03
  • 2013-04-17
  • 1970-01-01
  • 1970-01-01
  • 2011-04-20
  • 1970-01-01
  • 2012-07-31
  • 2021-01-02
  • 1970-01-01
相关资源
最近更新 更多