Can a map store class/struct?

Hello! :)

Can a map hold a struct / class that can then be used to create an object?

For example:

struct s1 {
int a = 0;
};

mymap["s1"] obj;
You can put objects of user-defined type into a std::map, if you tell the standard library how to hash those objects, but types are not objects and can never be manipulated at run-time.

Either I am seriously misunderstanding the question, or this appears to be an XY problem:
http://xyproblem.info/

What is your actual goal?
Last edited on
Hello mbozzi, thanks for your reply!

When the following code happens: s1 obj, the system creates an object from a definition run time, that definition is stored somewhere. If I could access that location/address it would be possible.
std::map<std::string, std::any> { { "s1", std::make_any<s1>() } };
Topic archived. No new replies allowed.