0

The compiler is unhappy with std::vector<std::string&>

And I don't understand why this is illegal

#include <vector>
#include <iostream>

std::string makeSetence(std::vector<std::string&> v) {
    std::string result;
    for (int i = 0; i < v.size(); i++) {
        auto w = v.at(i);

        result += w;

        if (i == v.size() - 1) {
            continue;
        }
        result += " ";
    }

    return result;
}

int main() {
    std::vector<std::string&> v;
    std::string test1 = "hello";
    v.push_back(test1);
    std::cout << makeSetence(v) << std::endl;
    return 0;
}
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
samol
  • 18,950
  • 32
  • 88
  • 127

0 Answers0