What does '&' mean in C++?

后端 未结 11 1603
隐瞒了意图╮
隐瞒了意图╮ 2021-01-18 02:20

What does \'&\' mean in C++?

As within the function

void Read_wav::read_wav(const string &filename)
{

}

And what is its equiv

11条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 02:52

    It means that the variable is a reference. There is no direct equivalent in C. You can think of it as a pointer that is automatically dereferenced when used, and can never be NULL, maybe.

    The typical way to represent a string in C is by a char pointer, so the function would likely look like this:

    void read_wav(struct Read_wav* instance, const char *filename)
    {
    }
    

    Note: the first argument here simulates the implicit this object reference you would have in C++, since this looks like a member method.

提交回复
热议问题