I am writing a program that passes around a struct type that I don't want to be modified. This struct has two const
members, and looks as follows:
struct system_s {
std::string name;
std::string pkg;
char *const start_cmd[10];
char *const end_cmd[10];
bool ros;
bool equals(const system_s &cmp);
};
The struct is being stored in a map with the following format. It is a class member:
std::map<std::string, system_s> sys_map;
There is another temporary map. Think of sys_map
as a cache if you prefer. But really you don't have to worry about how it is being used for the sake of this question. sys_map
is being called to add a system to the temporary map as follows. It is in a class method:
add_system(sys_map[msg->system]);
(*)
This function has the following definition. It is a class method:
int add_system(const system_s &sys);
When (*) is called, I get the following error:
system.h: In instantiation of ?std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::basic_string<char>; _Tp = system_s; _Compare = std::less<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, system_s> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = system_s; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::basic_string<char>]?:
/tc_manager_node.cpp:74:41: required from here
/system.h:26:8: error: uninitialized member ?system_s::start_cmd? with ?const? type ?char* const [10]? [-fpermissive]
struct system_s {
^
system.h:26:8: error: uninitialized member ?system_s::end_cmd? with ?const? type ?char* const [10]? [-fpermissive]
In file included from /usr/include/c++/4.8/map:61:0,
from /opt/ros/indigo/include/ros/console.h:42,
from /opt/ros/indigo/include/ros/ros.h:40,
from
/tc_manager_node.cpp:2: /usr/include/c++/4.8/bits/stl_map.h:469:59: note: synthesized method ?system_s::system_s()? first required here __i = insert(__i, value_type(__k, mapped_type()));
Why is this member of type system_s 'uninitialized'? It presumably stored already initialized in sys_map
. Does it have something to do with passing the system_s
as a reference in int add_system(const system_s &sys)
?