【发布时间】:2010-07-30 14:09:41
【问题描述】:
我正在研究 C++0x。当我查看tuple 时,我看到了这个例子。为什么我需要做get<3>(var)?为什么我不能var.get(index) 或var.get<index>()?我更喜欢这些以使代码看起来和感觉一致。
typedef tuple< int, double, long &, const char * > test_tuple ;
long lengthy = 12 ;
test_tuple proof( 18, 6.5, lengthy, "Ciao!" ) ;
lengthy = get<0>(proof) ; // Assign to 'lengthy' the value 18.
get<3>(proof) = " Beautiful!" ; // Modify the tuple’s fourth element.
【问题讨论】: