【发布时间】:2017-09-04 08:45:11
【问题描述】:
我有一个路点结构的双端队列,我需要提取一个特定的属性。
struct way_point
{
double time_stamp_s;
double lat_deg;
double long_deg;
double height_m;
double roll_deg;
double pitch_deg;
double yaw_deg;
double speed_ms;
double pdop;
unsigned int gps_nb;
unsigned int glonass_nb;
unsigned int beidou_nb;
};
例如我得到了
28729.257 48.66081132 15.63964745 322.423 1.1574 4.8230 35.3177 0.00 0.00 0 0 0
28731.257 48.66081132 15.63964744 322.423 1.1558 4.8238 35.3201 0.00 1.15 9 6 0
28733.257 48.66081132 15.63964745 322.423 1.1593 4.8233 35.3221 0.00 1.15 9 6 0
...
如果我需要 speed_ms 属性,我想取回一个数组,例如:
0.00
0.00
0.00
...
但是在函数之前不知道要提取的属性,这取决于需要。 我在想这样的功能:
function extract (string propertie_to_extract = "speed_ms", deque<struct way_point> way_point){
retrun vector[i]=way_point[i]."propertie_to_extract"}
【问题讨论】:
-
不,你不能在运行时形成变量名。另外,
extract("speed")比extract_speed()有什么优势?
标签: c++ struct properties extraction deque