makefile
-------------------------------------
%.o : %.cppg++ -g -c $< -o $@all: t t2 rmXX % : %.og++ $< -o $@rmXX:echo "rmXX"rm *.o
--------------------------------
同目录头文件:
hTestSTL.h
---------------------------------
#includeusing namespace std;class A {private:int a;int b;public:int aPlusB(){cout<<"a:"< < <<"b:"< < <<"b+b:"< < a=a;};void setB(int b){this->b=b;};};class NodeInfo{private:int beanId;int value;public:NodeInfo(){cout<<"init bean"< beanId=id; };void setValue(int value){this->value=value;};int getValue(){return this->value;};int getBeanId(){return this->beanId;};};
----------------------------
练习1
t1.cpp 队列容器
-----------------------------
#include#include "hTestSTL.h"#include using namespace std;queue que;void showHowUsingQueue(){ A a; A *p=&a; a.setA(100); a.setB(200); a.aPlusB(); que.push(*p); a.setA(1000); a.setB(2000); a.aPlusB(); que.push(*p); int tmp=0; A *tmp_p=0; while(!que.empty()) { que.pop(); tmp_p=&que.front(); tmp_p->aPlusB(); } cout< > b; return 0;};
---------------------
练习2 t2.cpp 访函数 迭代 遍历
------------------------
#include#include "hTestSTL.h"#include #include
#include using namespace std; void print( NodeInfo &elem) { cout< < void operator()( T& t ) { cout<<"printer:"< < beanList; NodeInfo bean; for(int i=0;i<20;i++) { bean.setValue(i); beanList.push_back(bean); } for_each(beanList.begin(), beanList.end(), print) ; cout<<"test2"<