???Java????C++???????????
???????????? ???????[ 2013/4/17 9:53:25 ] ????????
????2????Java?У?TreeMap????????????????????????????????????????int??double???????????????????????????C++?У?????ε?????????д?????????????Java???????TreeMap????????????????????????????C++????????????????????п??????????????????????????????????????????????????????????????ж???copy??????????????????????????????????????????????????????????????????????????????????????????Java????
public class MyTest {
private int _value;
public MyTest(int value) {
_value = value;
}
public static void main(String[] args) {
TreeMap<Integer??MyTest> tm = new TreeMap<Integer??MyTest>();
tm.put(5?? new MyTest(10));
System.out.println("The count of the TreeMap is " + tm.size());
Set<Entry<Integer??MyTest>> entries = tm.entrySet();
Iterator<Entry<Integer??MyTest>> it = entries.iterator();
while (it.hasNext()) {
Entry<Integer??MyTest> e = it.next();
System.out.printf("key = %d?? value = %d
"??e.getKey().intValue()??e.getValue()._value);
}
}
}
//The count of the TreeMap is 1
//key = 5?? value = 10
?????????Java???????????????????????????????????????C++????????????????????????????????μ????????C++?????????????????????????????????й?????????C++????????????
using namespace std;
class MyTest
{
public:
MyTest(int value) {
_value = value;
}
~MyTest() {}
public:
int getValue() const {
return _value;
}
private:
int _value;
};
int main()
{
map<int??MyTest*> m;
m.insert(make_pair(5??new MyTest(10)));
map<int??MyTest*>::iterator it = m.find(5);
printf("The count of the map is %d.
"??m.size());
it = m.begin();
for (; it != m.end(); ++it)
printf("key = %d?? value = %d
"??(*it).first??(*it).second->getValue());
return 0;
}
//The count of the map is 1
//key = 5?? value = 10
????????????????????????????Valgrind(Linux gcc)??BoundChecker(Visual C++)????????????????????????????MyTest???????????????????б?????????????????????й???????????????C++????
//?ú??????????????о??????????????
#define RELEASE_MAP(Type1??Type2??variable)
do {
map<Type1??Type2*>::iterator it = (variable).begin();
for (; it != (variable).end(); ++it)
delete (it->second);
(variable).clear();
} while(0)
int main()
{
map<int??MyTest*> m;
m.insert(make_pair(5??new MyTest(10)));
map<int??MyTest*>::iterator it = m.find(5);
printf("The count of the map is %d.
"??m.size());
it = m.begin();
for (; it != m.end(); ++it)
printf("key = %d?? value = %d
"??(*it).first??(*it).second->getValue());
RELEASE_MAP(int??MyTest??m);
return 0;
}
???????????????????????????????????????????????ж??????????й???????????????????????????????????????????????????????????????????????????й??????е????????????????????????й?????????C++?????д???Java?е?????????£????????????????????????????ò??????????????????C++??????????????????ò????????
?????????????????????????????????????????????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11