CS253 Duck Typing
A vector requires that its stored type be copyable, both via copy ctor and
assignment operator. For example, you can have a vector<string>
,
because strings are copyable
string now = "20241122T024848"; vector<string> v = {now, now, now}; cout << v.size() << '\n';
3
How about a non-copyable class?
class Mom { public: Mom() = default; // I like the default ctor. Mom(const Mom &) = delete; // You can’t change Mom! Mom &operator=(const Mom &) = delete; // You can’t change Mom! }; int main() { Mom helen; vector<Mom> v = {helen, helen, helen}; }
c.cc:10: error: use of deleted function 'Mom::Mom(const Mom&)'
Modified: 2017-05-09T21:25 User: Guest Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |