模板 - 在基类中访问受保护的typedef

时间:2016-06-13 11:29:08

标签: c++ xcode c++11

我一直在使用here中的树容器类。

在Visual Studio 2013中一切都很好(经过一次小修复),但我的应用程序是跨平台的,所以现在我试图让它在Xcode 7.2.1(Clang 1.0)中编译,并且所有地狱破裂了。

我有很多错误;我一直在看的那个,并且无法理解这个......(为了清楚起见,我已经修剪了一些内容)

template <typename Tree, typename Data, typename Compare>
struct node_ordered
: public node_base< Tree, 
                    node_ordered<Tree, Data, Compare>, 
                    multiset<   node_ordered<Tree, Data, Compare>*, 
                                ptr_less_data<Compare>, 
                                typename Tree::allocator_type> 
                                > 
    {
    typedef Tree tree_type;
    typedef typename Tree::allocator_type allocator_type;
    typedef node_ordered<Tree, Data, Compare> node_type;
    typedef multiset<node_type*, ptr_less_data<Compare>, allocator_type> cs_type;
    typedef node_base<Tree, node_type, cs_type> base_type;

    typedef typename base_type::iterator iterator;
    typedef typename base_type::const_iterator const_iterator;

    protected:
    typedef typename base_type::cs_iterator cs_iterator;
    typedef typename base_type::cs_const_iterator cs_const_iterator;

现在最后两行产生错误,

error: 'cs_iterator' is a protected member of 'st_tree::detail::node_base...

cs_iterator是该类的受保护成员,但该类是基类,所以它肯定应该有效吗?它在Visual Studio中实现,它似乎在G ++中(我从与问题#16相关的评论中推断出这一点。)

我尝试直接从:public node_base&lt; ..行复制和粘贴基类定义,以检查它是不是typedef的问题,我得到同样的错误。

正如我所说的,这段代码在Visual Studio 2013中编译并运行得很好。现在我已经习惯了Xcode / Clang在语法上比Visual C ++更严格,但这个(以及其他错误我&#39)我得知道,让我神秘化了。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在这里回答我自己的问题,所以人们不会浪费时间来帮助我。

事实证明,这个错误,以及我所看到的大部分错误,都是红色的鲱鱼。

我认为我在XCode而不是Visual Studio中编译差异的原因是由于编译器差异(这通常是罪魁祸首)。

但事实证明这是由于图书馆的不同。

XCode使用LLVM libcxx,其中包括一些其他人不会编译的编译时间。

例如在向量&lt;&gt;中定义,我们有

    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
              "Allocator::value_type must be same type as value_type");

现在在st_tree容器中,有些地方开发人员在内部值的向量声明中使用了为树值类型指定的分配器。

现在,当编译器遇到static_assert失败时,它会弹出一个错误,正如我所料,然后继续以非常破碎的方式,给出了一堆误导性错误,例如提示我发布的错误这个问题。

我已经通过开发人员向st_tree通知了他的代码问题。