头文件中的 C++ 'using' 和 'using typename'

ari*_*hal 3 c++ using header

在下面的 C++ 代码中,有人可以解释一下该部分中每一行的含义吗private?我试过查一下,但我仍然不明白他们是做什么的。

我知道这using相当于typedefC 中的内容。所以:

using the_graph = graph<T_node, T_edge1, T_allocator, T_size>;
Run Code Online (Sandbox Code Playgroud)

意味着你使用the_graph.

但是,在这种情况下,为什么要对其调用范围解析运算符呢?

我认为这不是这里描述的4 种方法中的任何一种。

template <class T_node, class T_edge1, class T_edge2, class T_allocator, class T_size = uint32_t>
class graph : private virtual graph<T_node, T_edge1, T_allocator, T_size>, private virtual graph<T_node, T_edge2, T_allocator, T_size>
{

public:

    using the_graph = graph<T_node, T_edge1, T_allocator, T_size>;


private:

    using typename the_graph::node_list_iterator;
    using the_graph::node_begin;
};
Run Code Online (Sandbox Code Playgroud)

R S*_*ahu 8

using指令用于将名称带入当前作用域,否则该名称不会带入当前作用域。

例子:

struct Foo
{
    struct Bar {};
};

int main()
{
   Bar b1; // Not ok. Bar is not in scope yet.

   using Foo::Bar;
   Bar b2; // Ok. Bar is now in scope.
}
Run Code Online (Sandbox Code Playgroud)

当名称依赖于模板参数时,标准要求您使用详细的形式

using typename the_graph::node_list_iterator;
Run Code Online (Sandbox Code Playgroud)

该行之后,您可以用作node_list_iterator类型名称。

不是the_graph类模板,您可以使用更简单的形式

using the_graph::node_list_iterator;
Run Code Online (Sandbox Code Playgroud)

进一步阅读:我必须在哪里以及为什么必须放置“template”和“typename”关键字?