1、auto、decltype

  auto是C++11中的关键字,它可以通过类型推导自动得到变量或对象的类型,需要注意的是auto会忽略引用,因为引用其实就代表原对象:

boost-数据类型之auto、any、tuple、variant
#include <vector>
#include "boost/assign.hpp"
using namespace boost::assign;

int main()
{
    auto i = 10;
    auto f = 12.34;
    auto s = string("abc");
    cout << i << ", " << f << ", " << s << endl;
    int num = i;
    double d = f;
    string str = s;

    vector<int> vc = list_of(1) (2) (3);
    auto iter = vc.begin();
    auto iterEnd = vc.end();
    for (; iter != iterEnd; iter++)
    {
        cout << *iter << endl;
    }

    return 0;
}
View Code

相关文章:

  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-16
  • 2021-09-30
  • 2021-10-17
猜你喜欢
  • 2022-02-04
  • 2021-05-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2021-08-09
  • 2022-02-14
相关资源
相似解决方案