开发者

datatype info over socket; dynamic initialize?

开发者 https://www.devze.com 2023-01-14 03:45 出处:网络
I have data coming over a socket that looks like this: (h)(int,char,f开发者_JAVA百科loat,int,char)(/h)(d)(2,a,1.32,45,d)(3,d,3.45,32,a)(/d)

I have data coming over a socket that looks like this:

(h)(int,char,f开发者_JAVA百科loat,int,char)(/h)(d)(2,a,1.32,45,d)(3,d,3.45,32,a)(/d)

The datatype of the data arriving is dynamic and is only known when the header is received. I then have to create corresponding std::vectors to store the data. In this case, two int, two char and one float vector. I don't know how to initialize in such a case. Can someone help me out?


std::vector can't do this by itself. It sounds like you need something that resembles Boost.Any or Boost.Variant, you'll need to decide which. If you have a small number of types, a simple union might work as well.


I think I understand. If a union contained all the datatypes, I could use one of them at any point of time and it can be initialized with the name of the union. Brilliant. Thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消