---
title: "再论c++的map使用"
author: "ouyida3"
date: "2013-08-16T15:49:24Z"
tags: []
categories: ["编程语言"]
slug: "c-map"
draft: false
lastmod: "2013-08-16T15:50:11Z"
id: 1926149
url: "https://ouyida3.iteye.com/blog/1926149"
---

前天Rao问我有一段代码运行时卡住了，不知道哪里有问题，我一看代码：

 

m\_MPpsDiscntAction.clear();

string sql = "SELECT a.action\_code,a.stat\_type,a.action\_type FROM table\_name a where a.stat\_type = 1  and  a.action\_type in(205,300,301)";

JTable* pTab = jdb::getConnect()-&gt;getJTable();

pTab-&gt;Clear();

pTab-&gt;AddSql(sql);

pTab-&gt;ExecSelect();

while(pTab-&gt;Fetch())

{

       m\_MPpsDiscntAction.insert(pair&lt;int,int&gt;(pTab-&gt;GetInt("ACTION\_CODE"),1));

}

 

 

 

非常短。因为现象是卡住，我首先怀疑sql运行过慢，他说在plsql运行过了，很快。

而下面的JTable操作都是公司框架的，不会有问题，于是我马上怀疑map的insert有问题。

首先怀疑的就是pair的使用。

果然，换成make\_pair&lt;int,int&gt;就OK了。

 

make\_pair和pair其实作用类似，make\_pair函数是转换为pair对象，而pair是强制的类型转换。

相对来说，一般更推荐用make\_pair。

pair在linux在测试过没问题，在aix上一商用，果然就出问题了。