【发布时间】:2017-12-16 03:02:16
【问题描述】:
考虑一个在头文件中定义的库
struct Proj {
struct Depth {
static constexpr unsigned Width = 10u;
static constexpr unsigned Height = 10u;
};
struct Video {
static constexpr unsigned Width = 10u;
static constexpr unsigned Height = 10u;
};
};
该库已编译,我现在正在开发一个链接到该库的应用程序。我想了很长时间,这是某种可见性问题,但即使在到处添加B_EXPORT(CMake 中的标准可见性东西)没有任何变化后,我终于找到了问题。
template <class Projection>
struct SomeApplication {
SomeApplication() {
unsigned height = std::max(// or std::max<unsigned>
Projection::Depth::Height,
Projection::Video::Height
);
}
};
我什至无法使用小型虚拟库/示例应用程序重现该问题。但是在应用程序中使用std::max会导致链接错误,而如果我只是自己做的话
unsigned height = Projection::Depth::Height;
if (height < Projection::Video::Height)
height = Projection::Video::Height;
一切顺利。 AKA 仅使用 Projection::XXX 的可见性似乎没有任何具体问题。
对可能导致这种情况的任何想法?这是在 OSX 上,所以this doesn't even apply。
【问题讨论】:
标签: c++11