variable structure name, is that possible?

Hey

is it possible to buit a structure with a variable name?

e.g .I've a n data files which I want to load and work with. Now I tought I could built a structure like the following:
1
2
3
4
5
6
7
8
9
10
struct datafile{
double data[511];
double mass;};

for(i=0; i<=n; i++)
{
string mystring = filename + i
datafile mystring
}


But how can I prevent that the structure name is "mystring" in stead of
filename1, filename2, filename3, ... ?
A

thank you for your time :)
I do not understand why do you need a structure instead of simple using std::string for the filenames?!
I think what he's trying to say is can he create a bunch of structs with identifiers that are composed of his filename string plus whatever iteration of the loop he's at.

So, what the above code is trying to achieve is a bunch of datafile structures, named filename 1 ... filename n.

In short, no, I don't think so. You're creating static instances there and, as such, the compiler needs to be aware of their name at compile time.
In this case maybe it is better to include a data member for a filename in the structure and use it as identifier. Or use std::map with key as filename and value as the structure.
Topic archived. No new replies allowed.