c++/oop---c++11 特性/类型

c++11

 

auto 关键字

自动判断变量的类型

查看代码
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
set<int>s;
int main(){
	for(int i=1;i<=10;i++)s.insert(rand());
	for(auto i=s.begin();i!=s.end();i++){
		printf("%d \n",*i);
	}
	return 0;
}

 

decltype

 

int i;
double t;
struct A { double x; };
const A* a = new A();
decltype(a) x1; // x1 is A *
decltype(i) x2; // x2 is int
decltype(a->x) x3; // x3 is double
decltype((a->x)) x4 = t; // x4 is double&
decltype (f()) x5 ;// x5 is the type of f 

 

posted @ 2022-04-17 11:12  liankewei123456  阅读(17)  评论(0编辑  收藏  举报