What does '&' mean in C++?

后端 未结 11 1604
隐瞒了意图╮
隐瞒了意图╮ 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

    References are aliases, they are very similar to pointers.

    std::string is an array of char with an explicit length (that is, there can be null characters embedded within).

    There is a C-library to emulate std::string (that is, provide an encapsulated interface) called bstring for Better String Library. It relieves you from the tedium of having to deal with two distinct variables (array and length).

    You cannot use classes in C, but you can emulate them with forwarded struct (to impose encapsulation) and class methods simply become regular functions with an explicit parameter.

    Altogether, this leads to the following transformation:

    void Read_wav::read_wav(const string &filename);
    
    void read_wav(struct Read_wav* this, struct bstring const* filename);
    

    Which (apart from the struct noise) is very similar to what you had before :)

提交回复
热议问题