模板类中的模板类的结构

时间:2016-02-25 08:34:16

标签: c++ templates c++11

告诉我为什么不能在另一个模板类中使用模板类的结构。 我个人认为这是合乎逻辑的。有c ++这样的功能吗? 我正在使用VS 2015.谢谢:)

template <typename T> struct Node
{
    T       value;
    Node*   next;
};

template<typename T> class MyList
{
public:
    Node<T>* root;
    //...
};

template<typename Type> class MyMap
{
public:
    struct ElementData
    {
        Type        types[32];
        unsigned    key;
    };

    Node<ElementData>* nodes;   
};

虽然这有效。

DocumentManager

1 个答案:

答案 0 :(得分:1)

您需要在此处添加typename(对于依赖类型名称jQuery(document).ready(function($) { $('.slideshow').royalSlider({ transitionType: 'move', randomizeSlides: false, imageScaleMode: 'fill' }); }); // Scrollify (snap to section) $(function() { $.scrollify({ section : "section", easing: "easeOutExpo", scrollSpeed: 1000, scrollbars: true, before:function() {}, after:function() {} }); $(".scroll-down").click(function(e) { e.preventDefault(); $.scrollify.next(); }); }); ),

MyList<ElementData>::Node
  

在声明或模板定义中,typename可用于声明依赖名称是一种类型。

请参阅Where and why do I have to put the “template” and “typename” keywords?