Hi, I am having difficulty understanding a couple of concepts in C++ from the C++ course.
Question 1a:
How does the compiler know where the corresponding source code for a header file is?
In unit5_exercise.cpp file:
we are telling the compilor that we are using the header file rosbot_class.h from the package rosbot_control. Now we are not mentioning the location of the corresponding source code for the header file, then, how does the compiler locate it?
Question 1b)
Is there a file structure we need to follow to create a header file and its corresponding source file, taking the rosbot_class as an example. (does header file always need to be in a folder called include
and does source file also need to in a folder called src.
Question 2:
In rosbot_class.cpp, which is the source file for the rosbot_class.h header file, we have a main() function as below. Here the main function is asking the robot to move using the rosbot.move() function.
#include "rosbot_control/rosbot_class.h"
.
.
.
int main(int argc, char **argv) {
ros::init(argc, argv, "rosbot_class_node");
RosbotClass rosbot;
rosbot.move();
float coordinate = rosbot.get_position(1);
ROS_INFO_STREAM(coordinate);
return 0;
}
The unit5_exercise.cpp file also has a main function, that tells it to move using function trajectory() (user defined)
#include "rosbot_control/rosbot_class.h"
.
.
.
int main(int argc, char **argv) {
ros::init(argc, argv, "Rosbot_move_node");
// CALL YOUR CLASS HERE
Avoid_WALL avoid_wall_obj;
avoid_wall_obj.trajectory();
}
Since we are using rosbot_class.cpp source code in unit5_exercise.cpp, does the robot respond to both the main() functions?
Feedback to @staff:
Though I figured most of it from google, It would have been great if the following concepts were explained in the course itself. :
-
How Pre-processor work
-
How compilation works
-
How Linker works
-
What is an Object file
-
Difference between <>and “” for #include files
While answering i would really appreciate it if you could quote the question using from above toolbar , making it easier to comprehend.
Thanks in advance.
-Joseph