简体   繁体   English

用名称中的作用域解析运算符声明一个指针

[英]Declaring a pointer with a scope resolution operator in the name

I'm trying to make sence of this tutorial on doubly linked lists. 我正在尝试在双向链表上使用本教程。 http://www.dreamincode.net/forums/topic/53161-how-to-create-a-basic-double-linked-list/ http://www.dreamincode.net/forums/topic/53161-how-to-create-a-basic-double-linked-list/

I can't understand this part 我听不懂这部分

  element* list::FirstEl = NULL;    //This initialises the static element* 'FirstEl' to  NULL  
  element* list::LastEl = NULL;     //This initialises the static element* 'LastEl' to  

I would say this code creates a pointer of type element with the name "list::FirstEl" and sets it to null, but the scope resolution operator makes me think there is something I still havn't covered in C++ yet. 我会说这段代码创建了一个名称为“ list :: FirstEl”的类型为type的指针,并将其设置为null,但是范围解析运算符使我认为C ++仍然没有涉及到某些东西。

What's going on here? 这里发生了什么?

That's a static class member initializtion. 那是static类成员初始化。

class list
{
    static element* FirstEl;
    static element* LastEl;
};

what you have there is the initialization of the members. 您所拥有的是成员的初始化。

The name of the variables are FirstEl and LastEl , but they are part of the class, that's why you have to qualify their names when you define them. 变量的名称是FirstElLastEl ,但是它们是类的一部分,这就是为什么在定义它们时必须限定其名称的原因。

Just like you'd qualify method names when you'd define them. 就像定义方法名称时要限定它们的名称一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM