Q:

Which, if any, of the following vector definitions are in error? For those that are legal, explain what the definition does. For those that are not legal, explain why they are illegal

0

Which, if any, of the following vector definitions are in error? For those that are legal, explain what the definition does. For those that are not legal, explain why they are illegal.

(a) vector<vector<int>> ivec;
(b) vector<string> svec = ivec;
(c) vector<string> svec(10, "null");

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <vector>
#include <string>

int main() {
  std::vector<std::vector<int>> ivec;
  // OK, a vector of vector of int, similar to 2-d int array
  //std::vector<std::string> svec = ivec;
  // Error: the type of `svec` and `ivec` doesn't match
  std::vector<std::string> svec2(10, "null");
  // OK, a vector of ten strings whose value are all "null"

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now