Dynamic declaration of vectors

closed account (1yvU5Di1)
I know there is no simple way of declaring variables dynamically in C++ but I'm looking for possible ways of passing in a vector to a function and somehow have the function declare new vectors based on names passed in to function.
I'm basically looking for tricks here...
Hi,

I am very very far of from being an expert, but I am fairly sure one can't do this in C++ - could well be wrong though.

My reasons are that I am fairly sure it's not possible to create a new type name from a string using templates, even with template template parameters. I suspect that is also true with template meta programming (TMP) for the same reason.

Maybe there are some template or TMP wizards out there to prove me wrong - it would be cool if that was the case :+)

It is possible to do this with the D language though :+)

Good Luck !!
Hi again,

You could use a std::map with a string as the key and a std::vector as the value, that would achieve the same thing as your OP.

Any clues as to what you want to do exactly?
It sounds like std::map<std::string, std::vector<BLAH>> is the desired container.
Last edited on
closed account (1yvU5Di1)
You guys..
I appreciate your comments :)
I was looking to avoid the map (in this case) but if there's no way to hack this limitation, I'll painfully rewrite my program and integrate maps.
Thanks.
It's not a limitation, the language is designed for you to use the standard containers such as std::map ;)
closed account (1yvU5Di1)
That's another way to see it.. hehe
Topic archived. No new replies allowed.