search

Home  >  Q&A  >  body text

c++ - 在写模板类时如何定义指向模板的指针的别名?

天蓬老师天蓬老师2808 days ago506

reply all(2)I'll reply

  • 阿神

    阿神2017-04-17 13:32:31

    template <typename Element>
    class Node {
    public:  // 加上限定符就好了
      typedef Node<Element>* PtrToNode;
    };
    
    int main() {
      Node<int>::PtrToNode p = new Node<int>;
      delete p;
    }

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:32:31

    template <typename Element>
    class Node {
    };
    
    template <typename Element>
    using PtrToNode = Node<Element>*;
    
    class C {};
    
    PtrToNode<C> p;

    For more information, see http://en.cppreference.com/w/cpp/language/type_alias

    reply
    0
  • Cancelreply