C++工作笔记-仿大佬“容器”风格
今天看别人的代码,发现大佬都喜欢把容器重新typedef下。又学到了一个装X手段。自己写了一段程序,用到了容器的typedef。代码如下:#include <iostream>#include <string>#include<vector>using namespace std;class Student{pub
·
今天看别人的代码,发现大佬都喜欢把容器重新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;
}
运行截图如下:
更多推荐
已为社区贡献20条内容
所有评论(0)