Philipp Kraus <philipp.kraus@flashpixx.de> wrote in news:k9v76e$9k9$1
@ariadne.rz.tu-clausthal.de:
Hello,
I would like to create a dynamic struct:
struct reg[] =
{
{ name1, *pointer },
{ name2, *pointer },
....
{ NULL, NULL }
}
name is a char / string and pointer a pointer to a function. I have got
a std::map<std::string, void*>
and need to create the struct above. So how can I create the struct
from my map? I need exactly
the struct structure, because I need to push it to a C function call.
typedef std::map<std::string, void*> mymap_t;
struct RegEntry {
const char* name;
void* pointer;
RegEntry(const mymap_t::value_type& x)
: name(x.first.c_str()), pointer(x.second) {}
RegEntry(): name(NULL), pointer(NULL) {}
};
mymap_t mymap = ...;
std::vector<RegEntry> reg(mymap.begin(), mymap.end());
reg.push_back(RegEntry()); // the (0,0) terminator
callcfunction(®[0], ...);
The crucial point to note here is that the map may not be deleted or
altered while reg is alive, otherwise the name pointers in reg would
become invalid.
Thanks a lot, I miss the forest for the trees. Defining a struct for
the reference of the first element to the C function.