samedi 2 mars 2019

How to pass rvalue reference from caller to callee

Say I have code below

#include <iostream>

void foo(std::string && s) { std::cout << s; }

void bar(std::string && s) { foo(s); }

int main() {

  bar("abc");

  return 0;
}

I got compiling error:

error: cannot bind ‘std::string {aka std::basic_string}’ lvalue to ‘std::string&& {aka std::basic_string&&}’ void bar(std::string && s) { foo(s); }

Aucun commentaire:

Enregistrer un commentaire