1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include <iostream> #include <map> #include <unordered_map>// c++11後才支援此head file using namespace std; class Block { public: Block(int x, int y):x(x),y(y){}; Block(){}; ~Block(){}; int getX(){return x;}; int getY(){return y;}; private: int x,y; }; int main() { map<int, Block> t1; map<int, Block*> t2; t1[ 1 ] = Block (3,5); t1[ 2 ] = Block (4,6); t2[ 1 ] = new Block(3,5); t1.find(1); t1.find(1)->first; t1.find(1)->second; t1.count(1); t1.at(1); t1.erase(1); t1.erase(t1.find(2)); t1.size(); return 0; }
|