1

I was reading some C++ code but couldn't figure out what line:

using unique_ptr<Node<Key, Data>>::unique_ptr;

in the following code block means:

...
using std::unique_ptr;

template <class Key, class Data>
class Node;

template <class Key, class Data>
class Tree : public unique_ptr<Node<Key, Data>>
{
    using unique_ptr<Node<Key, Data>>::unique_ptr;

    // Copy constructor
    Tree(unique_ptr<Node<Key, Data>>&tree) {
        *this = tree;
    }

    // Move constructor
    Tree(unique_ptr<Node<Key, Data>>&& tree) : 
         unique_ptr<Node<Key, Data>> (move(tree)) {
    }
    ...
}

template <class Key, class Data>
class Node {
    ...
}

I thought the keyword using in combination with :: was used to import an attribute or function of that class. What does the line do?

P.S.: In the Node class there are no attributes or functions that are called unique_ptr.

  • 4
    I'm skeptical that the design decision to **publicly inherit from `std::unique_ptr`** can ever end well. – François Andrieux Jul 31 '18 at 15:28
  • "What does the line do?" it does exactly that - imports a function. In this case name of function matches name of the class. – Slava Jul 31 '18 at 15:30

0 Answers0