to************@ gmail.com wrote:
I don't think this is possible but, if anyone has comments on a work
around that would be great. Let me explain the reason I would like to
do this. Suppose you are given a file that contains a header defining
a structure for a set of data that is contained in the file. If you do
not know what the structure is before you read the header of the file
how would you work with this in code?
A factory class has been suggested, but may not be suitable in this
case. A factory class basically requires that you pre-define all the
possible structure types that might be read in, and then based on the
data in the file it decides which of those to create.
It sounds like your inputs form an unconstrained set -- i.e. you can't
pre-define all the possible inputs. Under these circumstances, I'd
consider representing each data item as something like an
std::vector<boo st::any>. In particular, structs require that you
hard-code struct member names in your code, and under the
circumstances, you don't even know how many names there will be, not to
mention what their names or types are. With a vector, you can have an
arbitrary number of items and you don't need a name for each -- you
just need a number. It sounds like you'll format these as something
like "channel %d" during output (except we'll hope you're not really
using printf) which makes the numbers pretty easy to deal with anyway.