InterviewSolution
Saved Bookmarks
| 1. |
Which is the following is syntactically correct for vector v?(a) vector :: const_iterator itr = v.rbegin();(b) vector :: reverse_iterator itr = v.begin();(c) vector :: iterator itr = v.begin();(d) vector :: iterator itr = v.cbegin();I have been asked this question in class test.This interesting question is from seq_con Vector Class in chapter Class Hierarchies, Library & Containers of C++ |
|
Answer» CORRECT option is (c) vector To explain I would say: v.rbegin() returns itertor of reverse iterator therefore cannot be stored in const_iterator(TYPE MISMATCH). Similarly v.begin() returns normal iterator therefore cannot be stored in reverse_iterator and v.cbegin() returns the const_iterator therefore cannot be stored in normal iterator. |
|