不要试图编写独立于容器类型的代码
本节条款作者想要表达的意思很简单,就是我们不应该认为容器很完美,不能在编写新的容器时涵盖所有特性,这么做是不现实的,要根据程序需求,提取出关键需求特性。
我们为了以后灵活的改动程序或者简化编程要经常用typedef关键字。
如下代码:
#include<iostream>
#include<vector>
using namespace std;
class What
{
public:
//............
};
typedef vector<What>::iterator WhatPoint;
typedef vector<What> TypeWhat;
int main()
{
What w;
TypeWhat what;
what.push_back(w);
WhatPoint w1 = find(what.begin(), what.end(), w);
}
如上代码,typedef可以使代码更加简洁,并且容易改动。
原文:http://blog.csdn.net/u011058765/article/details/46380841