tags:

views:

29

answers:

2

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

(h)(int,char,float,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?

+1  A: 

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.

Thanatos
The number of datatypes are about 10. How can a union help?
Rajesh
A: 

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!

Rajesh