Rvalue Reference is Treated as an Lvalue?

后端 未结 4 1356
小蘑菇
小蘑菇 2020-11-22 09:20

I posted this answer: https://stackoverflow.com/a/28459180/2642059 Which contains the following code:

void foo(string&& bar){
    string* temp = &         


        
4条回答
  •  悲哀的现实
    2020-11-22 10:07

    Here in this case named rvalue references are lvalues, while if the input type is const named rvalue references then it will be rvalue, here is a simple example:

    #include 
    #include 
    
    void foo(const std::string&& bar) { 
        std::string* temp = &bar; // compile error, can't get address
        std::cout << *temp << " @:" << temp << std::endl;
    }
    
    int main()
    {
        foo("test");
        return 0;
    }
    

    Hope this is useful.

提交回复
热议问题