课程: C++ Development: Advanced Concepts, Lambda Expressions, and Best Practices
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
The any class - C++教程
课程: C++ Development: Advanced Concepts, Lambda Expressions, and Best Practices
The any class
- The any class was introduced with C plus plus 17 to provide a type safe polymorphic container for a single object of any type. This is any.cpp from chapter five of the exercise files. You see we're including the any header. We have a string header and a vector header we're going to be using those as well. We have this function which takes a object of type any, and it prints out its contents and so it first checks if it has a value, and otherwise it checks its type. So the any class has this method type which returns a typeid object and we compare it with the typeid of an int and if it matches then we have a value of type int and we use any cast to retrieve that value. And we put it in the X variable here and we print it out. Otherwise we compare its type to the typeid of a standard string object and we handle that. Otherwise we test for a vector of int and we handle that. And otherwise we…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。