今天看别人的代码,发现大佬都喜欢把容器重新typedef下。

又学到了一个装X手段。

自己写了一段程序,用到了容器的typedef。

代码如下:

#include <iostream>
#include <string>
#include<vector>
using namespace std;

class Student{
public:
	Student(string name, int id, int sex, int age){
		m_id = id;
		m_name = name;
		m_sex = sex;
		m_age = age;

	}
	void printAll(){
		cout << "(" << m_id << "," << m_name << "," << m_age << "," << m_sex << ")" << endl;
	}

private:
	string m_name;
	int m_id;
	char m_sex;
	int m_age;
};

typedef vector<Student*> StudentVec;

void main(){
	StudentVec studentVec;
	studentVec.push_back(new Student("朱小明", 10085, 'M', 20));
	studentVec.push_back(new Student("妹爷", 10082, 'M', 79));
	studentVec.push_back(new Student("闰土", 10057, 'M', 25));
	studentVec.push_back(new Student("球球", 10055, 'W', 24));
	studentVec.push_back(new Student("腿腿", 10051, 'W', 24));
	studentVec.push_back(new Student("泡泡", 10057, 'M', 8));

	StudentVec::iterator iter;
	for (iter = studentVec.begin(); iter != studentVec.end(); iter++){
		(*iter)->printAll();
	}

	getchar();
	return;
}

运行截图如下:



Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐