What does '&' mean in C++?

后端 未结 11 1675
隐瞒了意图╮
隐瞒了意图╮ 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 03:06

    In this particular case, std::string has a c_str method which returns a const char *. You can make a parallel C version and then have your C++ do something like:

    void Read_wav::read_wav(const string &filename)
    {
        do_read_wav(internal_read_wav, filename.c_str());
    }
    

    where do_read_wav is your C routine and internal_read_wav is a pointer to a C-style struct.

    void do_read_wav(struct Read_wav rw, const char * filename)
    

    Now, if you are storing information in the class, you need to make a C struct [all of the fields must be POD, etc]

提交回复
热议问题