Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 这是什么,这是什么_C++_C++17 - Fatal编程技术网

C++ 这是什么,这是什么

C++ 这是什么,这是什么,c++,c++17,C++,C++17,我有一个简单的初学者问题。以下是代码块: SimpleString& operator=(const SimpleString& other) { if(this == &other) return *this; const auto new_buffer = new char[other.max_size]; delete[] buffer; buffer = new_buffer; length = other.

我有一个简单的初学者问题。以下是代码块:

  SimpleString& operator=(const SimpleString& other) {
    if(this == &other)
      return *this;
    const auto new_buffer = new char[other.max_size];
    delete[] buffer;
    buffer = new_buffer;
    length = other.length;
    max_size = other.max_size;
    std::strncpy(buffer, other.buffer, max_size);
    return *this;
  }
以下是完整的代码:

我不明白,为什么这是第二行的指针
*第三行中的这个
也应该是指针,因为方法的返回类型必须是指针。 在我看来,第三行也应该是
这个
,而不是
*这个


任何人至少有一个解释链接。

方法的返回类型是引用而不是指针。在
SimpleString&
中,
&
表示引用,指针应该是
SimpleString*

返回类型是引用,而不是指针。@tkausl see引用是指针,但是常量指针。@barlop这是一个实现细节。@tkausl这是一个与,(表明是错的?)引用不是指针的想法。据我所知,指针是地址,引用也是地址。问题是人们谈论的是存储在内存位置的地址,还是内存位置的地址(不从内存位置获取地址).@barlop这是一个非常混乱的解释。引用不是指针,您正在考虑如何实现它们,但从语言的角度来看,它们是不同的实体。我理解,指针和引用之间存在差异。但这不是我的核心问题。该方法希望返回一个引用t返回指针?如果
p
是指向某个对象的指针,则表达式
*p
是对同一对象的引用。