In C++, what does & mean after a function's return type?

后端 未结 11 1439
情歌与酒
情歌与酒 2020-11-29 23:49

In a C++ function like this:

int& getNumber();

what does the & mean? Is it different from:

int getNumb         


        
11条回答
  •  独厮守ぢ
    2020-11-30 00:21

    Yes, the int& version returns a reference to an int. The int version returns an int by value.

    See the section on references in the C++ FAQ

提交回复
热议问题