如何声明某个结构的成员变量类型的变量?
how to declare a var of the type of a member var of some struct?
我想获得这样的代码:
struct Order_t {
time_point<system_clock, microseconds> order_time;
// some other fileds
};
template<typename Dura>
void onTimer( time_point<system_clock, Dura> tp_now ) {
auto tp0 = time_point_cast<Order_t::order_time::duration>( tp_now );
// some other codes...
};
但是这些都无法编译。事实上,我需要声明一个与 Order_t::order_time
具有相同类型的变量,但这里没有类型的变量。
要获得嵌套类型 (::duration
),您需要一个类型,而不是变量。因此,应该是
auto tp0 = time_point_cast<decltype(Order_t::order_time)::duration>(tp_now);
我想获得这样的代码:
struct Order_t {
time_point<system_clock, microseconds> order_time;
// some other fileds
};
template<typename Dura>
void onTimer( time_point<system_clock, Dura> tp_now ) {
auto tp0 = time_point_cast<Order_t::order_time::duration>( tp_now );
// some other codes...
};
但是这些都无法编译。事实上,我需要声明一个与 Order_t::order_time
具有相同类型的变量,但这里没有类型的变量。
要获得嵌套类型 (::duration
),您需要一个类型,而不是变量。因此,应该是
auto tp0 = time_point_cast<decltype(Order_t::order_time)::duration>(tp_now);