Q:

Is the following declaration legal? If not, why not

0

 Is the following declaration legal? If not, why not?

vector<NoDefault> vec(10);

All Answers

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

It is illegal, the constructor of `vector` taken a single number will call the default constructor of elements to value initialze its elements, but the class of the elements `NoDefault` does not have a default constructor, thus the code will not compile.

 

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

It is illegal, the constructor of `vector` taken a single number will call the default constructor of elements to value initialze its elements, but the class of the elements `NoDefault` does not have a default constructor, thus the code will not compile.

 

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

total answers (2)

Similar questions


need a help?


find thousands of online teachers now