ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
First: this is all basic C++ and should have been asked on a more suitable forum (like Stack Overflow or similar). If you're new with C++ (and ROS), I would really recommend not trying to learn the two at the same time, as it's going to complicate things.
Having said that, see below for some comments on why the compiler is complaining.
In function ‘void diagnosticCallback(const DiagnosticArrayPtr&)’: /home/default_ws/src/err_pack/src/errors_node.cpp:52:21: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’ if (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::ERROR) ^
diag_msgs
is of pointer type, so right now you're indexing against the raw pointer itself, not what it is pointing to (which is a diagnostic_msgs/DiagnosticArray).
If you want access to the array with messsages, I believe you should also be accessing the status
field.
/home/default_ws/src/err_pack/src/errors_node.cpp:54:7: error: ‘errorcode’ was not declared in this scope errorcode = NodeToErrorCode[diags_msg[0].name]; ^
There is no errorcode
variable anywhere in the code you show, so this is the compiler telling you that.
/home/default_ws/src/err_pack/src/errors_node.cpp:54:19: error: ‘NodeToErrorCode’ was not declared in this scope errorcode = NodeToErrorCode[diags_msg[0].name]; ^
There is no ‘NodeToErrorCode’
variable anywhere in the code you show, so this is the compiler telling you that.
/home/default_ws/src/err_pack/src/errors_node.cpp:54:47: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’ errorcode = NodeToErrorCode[diags_msg[0].name]; ^
This is the same problem as on line 54
.
(I'm going to skip the other occurrences of this)
/home/default_ws/src/err_pack/src/errors_node.cpp:55:18: error: ‘requestStart’ was not declared in this scope requestStart(); ^
That function is defined later, so the compiler can't find it at this point.
Additionally requestStart(..)
takes an errorLib::errorH&
argument that you are not providing.
/home/default_ws/src/err_pack/src/errors_node.cpp:60:21: error: ‘requestNotStart’ was not declared in this scope requestNotStart(); ^
Same problem as on line 55
.
/home/default_ws/src/err_pack/src/errors_node.cpp: In function ‘int requestStart(errorLib::errorH&)’: /home/default_ws/src/err_pack/src/errors_node.cpp: In function ‘int main(int, char**)’: /home/default_ws/src/err_pack/src/errors_node.cpp:93:53: error: no matching function for call to ‘errorLib::errorH::errorH(const char [21], int)’ errorLib::errorH c("For starting/ending", 2); ^
The ctor you've defined takes three args (EC value, string text, int sec
), you're supplying it with two.
2 | No.2 Revision |
First: this is all basic C++ and should have been asked on a more suitable forum (like Stack Overflow or similar). If you're new with C++ (and ROS), I would really recommend not trying to learn the two at the same time, as it's going to complicate things.
Having said that, see below for some comments on why the compiler is complaining.
In function ‘void diagnosticCallback(const DiagnosticArrayPtr&)’: /home/default_ws/src/err_pack/src/errors_node.cpp:52:21: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’ if (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::ERROR) ^
diag_msgs
is of pointer type, so right now you're indexing against the raw pointer itself, not what it is pointing to (which is a diagnostic_msgs/DiagnosticArray).
If you want access to the array with messsages, I believe you should also be accessing the status
field.
/home/default_ws/src/err_pack/src/errors_node.cpp:54:7: error: ‘errorcode’ was not declared in this scope errorcode = NodeToErrorCode[diags_msg[0].name]; ^
There is no errorcode
variable anywhere in the code you show, so this is the compiler telling you that.
/home/default_ws/src/err_pack/src/errors_node.cpp:54:19: error: ‘NodeToErrorCode’ was not declared in this scope errorcode = NodeToErrorCode[diags_msg[0].name]; ^
There is no ‘NodeToErrorCode’
variable anywhere in the code you show, so this is the compiler telling you that.
This statement is also confusing: from the capitalisation I expect this to be a constructor, but the [
make it seem like this is a std::map
or something similar.
Suggestion: use lower case for variable names only (ROS uses the Google C++ code style convention).
/home/default_ws/src/err_pack/src/errors_node.cpp:54:47: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’ errorcode = NodeToErrorCode[diags_msg[0].name]; ^
This is the same problem as on line 54
.
(I'm going to skip the other occurrences of this)
/home/default_ws/src/err_pack/src/errors_node.cpp:55:18: error: ‘requestStart’ was not declared in this scope requestStart(); ^
That function is defined later, so the compiler can't find it at this point.
Additionally requestStart(..)
takes an errorLib::errorH&
argument that you are not providing.
/home/default_ws/src/err_pack/src/errors_node.cpp:60:21: error: ‘requestNotStart’ was not declared in this scope requestNotStart(); ^
Same problem as on line 55
.
/home/default_ws/src/err_pack/src/errors_node.cpp: In function ‘int requestStart(errorLib::errorH&)’: /home/default_ws/src/err_pack/src/errors_node.cpp: In function ‘int main(int, char**)’: /home/default_ws/src/err_pack/src/errors_node.cpp:93:53: error: no matching function for call to ‘errorLib::errorH::errorH(const char [21], int)’ errorLib::errorH c("For starting/ending", 2); ^
The ctor you've defined takes three args (EC value, string text, int sec
), you're supplying it with two.