What does `invalid initialization of non-const reference` mean?

后端 未结 1 2043
谎友^
谎友^ 2020-12-07 01:41

When compiling this code I get the following error:

In function \'int main()\': Line 11: error: invalid initialization of non-const reference of typ

相关标签:
1条回答
  • 2020-12-07 02:15

    In C++ temporaries cannot be bound to non-constant references.

    Main<int> &mainReference = Main<int>::tempFunction();

    Here you are trying to assign the result of an rvalue expression to a non-constant reference mainReference which is invalid.

    Try making it const

    0 讨论(0)
提交回复
热议问题