使用std:.pair吧 [英] Using std:.pair right

查看:65
本文介绍了使用std:.pair吧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用std :: pair进行了这个小测试:


test< intt1(1);

test< intt2(2);

std :: pair< test< int> ;,test< int mypair = std :: make_pair(t1,t2);


其中test是模板类我写。看起来有点麻烦

做一对比上面的程序有更好的方法吗?

解决方案

desktop写道:


我用std :: pair进行了这个小测试:


test< intt1(1) ;

test< intt2(2);

std :: pair< test< int> ;,test< int mypair = std :: make_pair(t1,t2);


其中test是我写的模板类。看起来有点麻烦

做一对比上面的程序有更好的方法吗?



你会建议什么?


-

Ian Collins。


desktop< ff*@sss.com在新闻中写道:f4 ********** @ news.net.uni-c.dk:
< blockquote class =post_quotes>
我用std :: pair进行了这个小测试:


test< intt1(1);

test< intt2(2);

std :: pair< test< int> ;,test< int mypair = std :: make_pair(t1,t2);


其中test是我写的模板类。看起来有点麻烦

制作一对比上面的程序有更好的方法吗?



你会怎么做它更容易? std :: pair需要知道每个

的类型,你的模板类需要知道它的模板类型。

你在哪里看到哪里可以更容易?




6/15/07 4:30 PM,在文章f4 ****** ****@news.net.uni-c.dk,桌面

< ff*@sss.comwrote:


我用std :: pair进行了这个小测试:


test< intt1(1);

test< intt2(2);

std :: pair< test< int> ;,test< int mypair = std :: make_pair(t1,t2);


其中test是模板类I中写道。看起来有点麻烦

做一对比上面的程序有更好的方法吗?



是:


test< intt1(1);

test< intt2(2 );


auto mypair = std :: make_pair(t1,t2);


不幸的是,你需要一个已经实现的C ++编译器这个C ++ 09

功能,以便编译此代码。


Greg

I have made this little test with std::pair:

test<intt1(1);
test<intt2(2);
std::pair<test<int>,test<int mypair = std::make_pair(t1,t2);

where test is a template class I wrote. It seems a bit cumbersome to
make a pair are there any better way to do it than the above procedure?

解决方案

desktop wrote:

I have made this little test with std::pair:

test<intt1(1);
test<intt2(2);
std::pair<test<int>,test<int mypair = std::make_pair(t1,t2);

where test is a template class I wrote. It seems a bit cumbersome to
make a pair are there any better way to do it than the above procedure?

What would you suggest?

--
Ian Collins.


desktop <ff*@sss.comwrote in news:f4**********@news.net.uni-c.dk:

I have made this little test with std::pair:

test<intt1(1);
test<intt2(2);
std::pair<test<int>,test<int mypair = std::make_pair(t1,t2);

where test is a template class I wrote. It seems a bit cumbersome to
make a pair are there any better way to do it than the above procedure?

How would you make it easier? std::pair needs to know the type of each of
its halves, Your template class needs to know what type it''s templated on.
Where do you see where it could be made easier?



On 6/15/07 4:30 PM, in article f4**********@news.net.uni-c.dk, "desktop"
<ff*@sss.comwrote:

I have made this little test with std::pair:

test<intt1(1);
test<intt2(2);
std::pair<test<int>,test<int mypair = std::make_pair(t1,t2);

where test is a template class I wrote. It seems a bit cumbersome to
make a pair are there any better way to do it than the above procedure?

Yes:

test<intt1(1);
test<intt2(2);

auto mypair = std::make_pair(t1, t2);

Unfortunately, you will need a C++ compiler that has implemented this C++09
feature in order for this code to compile.

Greg


这篇关于使用std:.pair吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆