# Clarification on the content of C++ for Robotics Basics

**URL:** <https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293>\
**Category:** C++ For Robotics\
**Created:** [February 7, 2022, 10:54am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293 "2022-02-07T10:54:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph1001](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/joseph1001/32/7077_2.png) [@Joseph1001](https://get-help.theconstruct.ai/u/Joseph1001)\
**Post date:** [February 7, 2022, 10:54am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/1 "2022-02-07T10:54:09Z")

</div>

Hi, i am familiar with using Python inROS and was learning to do this in C++, using the course **C++ For Robotics**. I have a couple of queries regarding the course.

**Question 1:**  
Under **Unit 1** , **unit1\_exercise.cpp**

```auto
#include "rosbot_control/rosbot_class.h"
#include <ros/ros.h>

```

- What is the difference between " " and \<\> based on usage above? from my understanding the syntax is `#include <Package_name/header_file.h>`, so why are we using " " ?

**Question 2:**  
Under **Unit 1,**  **unit1\_exercise.cpp**

```auto
int main(int argc, char **argv) {
  ros::init(argc, argv, "rosbot_node");

```

- What is \*\*argv? is it a pointer? In the course content we talk about using pointers that use a single \* to get the value at an address, but there is no mention of \*\* in the content? Can i know what this is intended to do?

- I understand from the content that pointers are used in functions to avoid data duplication (like say when passing array into a function) and to make things faster. Can i know how this problem is addressed in python since i have rarely used pointer when working on ROS with python?

**Question 3:**  
Under **Unit 1,**  **unit1\_exercise.cpp**

```auto
#include "rosbot_control/rosbot_class.h"
#include <ros/ros.h>

int main(int argc, char **argv) {
  ros::init(argc, argv, "rosbot_node");

  RosbotClass rosbot;
  rosbot.move();

```

When working with Python files, in order to use a class, I had to specifically import the class as  
`from python_file_name import Class_written_in_python_file`

or i had to import the entire module and use dot operator as below :

```auto
import python_module
python_module.Class_written_in_python_file

```

**Question**  
When we write the line **`#include "rosbot_control/rosbot_class.h"`** , is all its contents readily available to use directly?

We have used **`RosbotClass rosbot;`** directly without any dot operator or anything. Also in **`ROS_INFO_STREAM(x_2 << " and " << y_2);`**, we are able to use the function **ROS\_INFO\_STREAM** directly.

At the same time, we are using scope operator in **`ros::init`** to access it. Why the two different approaches?

**Question 4:**

```auto
class Hobbit {
    public:
    
       Hobbit(string a,float b,int c) {
           name = a;
           height = b;
           age = c;
       } //constructor
    
       string name;
       float height; //in meters
       int age;

```

When creating a constructor, why are the data types (`string name; float height; //in meters int age;`), mentioned after the constructor is defined? Since the constructor is compiled first, how will the program know the datatype of say “name” when its called before its defined.

**Question 5:**

- What the difference between scope operator and namespace? since **cout** can be used using **namespace std** as well as **std:: cout**.

**Question 6:**  
In Unit 5, **rosbot\_class.h** ,

```auto
#ifndef ROSBOT_CLASS_H
#define ROSBOT_CLASS_H
#include "geometry_msgs/Twist.h"
#include "nav_msgs/Odometry.h"
#include "sensor_msgs/LaserScan.h"
#include <list>
#include <ros/ros.h>
#include <string>

```

What do the first two lines mean?

* * *

* * *

I am new to C++ and these clarification would really help. thanks in advance. 😀

---

<div class="post-metadata">

**Author:** ![rupaligarewal22](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rupaligarewal22/32/10_2.png) [@rupaligarewal22](https://get-help.theconstruct.ai/u/rupaligarewal22)\
**Post date:** [February 7, 2022, 10:59am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/2 "2022-02-07T10:59:39Z")

</div>

Hi @Joseph1001,

Answer to your question 1 is telling preprocessor where to find the header file in need. By using \<\> you tell preprocessor to use the usual path whereas using “” tells preprocessor to first search the directory in which this file is stored for the required header.

---

<div class="post-metadata">

**Author:** ![rupaligarewal22](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rupaligarewal22/32/10_2.png) [@rupaligarewal22](https://get-help.theconstruct.ai/u/rupaligarewal22)\
**Post date:** [February 7, 2022, 11:06am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/3 "2022-02-07T11:06:09Z")

</div>

Answer to question 2 is, single \* stands for a pointer, double \* means pointer to a pointer. This is multiple indirection concept of c++. You can read more about it here [https://www.tutorialspoint.com/cplusplus/cpp\_pointer\_to\_pointer.htm](https://www.tutorialspoint.com/cplusplus/cpp_pointer_to_pointer.htm).

Concept is same for python as well.

---

<div class="post-metadata">

**Author:** ![Joseph1001](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/joseph1001/32/7077_2.png) [@Joseph1001](https://get-help.theconstruct.ai/u/Joseph1001)\
**Post date:** [February 7, 2022, 11:09am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/4 "2022-02-07T11:09:10Z")

</div>

Thanks for replying @rupaligarewal22.  
When we use the \<\>, you said the preprocessor takes the usual path, is there a general directory where all the \<\> files are stored?

With “”, you said that preprocessor searches for the file `/rosbot_class.h` in the package `rosbot_control`, does the preprocessor already know the location of the `rosbot_control` package?

---

<div class="post-metadata">

**Author:** ![rupaligarewal22](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rupaligarewal22/32/10_2.png) [@rupaligarewal22](https://get-help.theconstruct.ai/u/rupaligarewal22)\
**Post date:** [February 7, 2022, 11:10am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/5 "2022-02-07T11:10:27Z")

</div>

@Joseph1001 answer to question 3 is: first understand how header files work in cpp. Header files in cpp contains a well written code which you can access just by including the header file.  
Different language follows different syntax but the concept is same i.e. write code such as to be able to reuse them in times of need.

---

<div class="post-metadata">

**Author:** ![Joseph1001](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/joseph1001/32/7077_2.png) [@Joseph1001](https://get-help.theconstruct.ai/u/Joseph1001)\
**Post date:** [February 7, 2022, 11:12am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/6 "2022-02-07T11:12:12Z")

</div>

> [@rupaligarewal22](#):
>
> Answer to question 2 is, single \* stands for a pointer, double \* means pointer to a pointer. This is multiple indirection concept of c++. You can read more about it here [C++ Pointer to Pointer (Multiple Indirection)](https://www.tutorialspoint.com/cplusplus/cpp_pointer_to_pointer.htm).
> 
> Concept is same for python as well.

Thanks for sharing the link, it was informative. Can you tell me why we use it? We can use a single pointer also to point to an address, then why two?

---

<div class="post-metadata">

**Author:** ![rupaligarewal22](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rupaligarewal22/32/10_2.png) [@rupaligarewal22](https://get-help.theconstruct.ai/u/rupaligarewal22)\
**Post date:** [February 7, 2022, 11:12am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/7 "2022-02-07T11:12:22Z")

</div>

@Joseph1001 refer this [https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename](https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename)

---

<div class="post-metadata">

**Author:** ![rupaligarewal22](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rupaligarewal22/32/10_2.png) [@rupaligarewal22](https://get-help.theconstruct.ai/u/rupaligarewal22)\
**Post date:** [February 7, 2022, 11:15am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/8 "2022-02-07T11:15:29Z")

</div>

@Joseph1001 check this out  
[https://stackoverflow.com/questions/71108/to-what-use-is-multiple-indirection-in-c/71250](https://stackoverflow.com/questions/71108/to-what-use-is-multiple-indirection-in-c/71250)

Not every time you have access rights directly to a data structure. Using multiple indirection makes sure you play around without outsider telling whats in the main code.

---

<div class="post-metadata">

**Author:** ![rupaligarewal22](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rupaligarewal22/32/10_2.png) [@rupaligarewal22](https://get-help.theconstruct.ai/u/rupaligarewal22)\
**Post date:** [February 7, 2022, 11:17am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/9 "2022-02-07T11:17:51Z")

</div>

@Joseph1001 that’s the beauty of **templates**. Just write a generic code and on the go you can define the data type and all the functions will still be usable. Read more about template to know the background story.

---

<div class="post-metadata">

**Author:** ![Joseph1001](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/joseph1001/32/7077_2.png) [@Joseph1001](https://get-help.theconstruct.ai/u/Joseph1001)\
**Post date:** [February 7, 2022, 11:34am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/10 "2022-02-07T11:34:26Z")

</div>

Thanks @rupaligarewal22 , this was really helpful.

I will also do a couple of courses from other sites in addition to Construct to work better with C++.

I think since the content in this course is tailored mainly towards application in ROS, they did not go into depth.

Thanks for taking the time. 😀

---

<div class="post-metadata">

**Author:** ![rupaligarewal22](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rupaligarewal22/32/10_2.png) [@rupaligarewal22](https://get-help.theconstruct.ai/u/rupaligarewal22)\
**Post date:** [February 7, 2022, 11:37am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/11 "2022-02-07T11:37:21Z")

</div>

> [@Joseph1001](#):
>
> perator and namespace? since **cout** can be used using **namespace std** as well as **std:: cou**

The using namespace statement just means that in the scope it is present, make all the things under the std namespace available without having to prefix std:: before each of them. Refer this article [https://www.tutorialspoint.com/What-does-using-namespace-std-mean-in-Cplusplus](https://www.tutorialspoint.com/What-does-using-namespace-std-mean-in-Cplusplus)

---

<div class="post-metadata">

**Author:** ![rupaligarewal22](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rupaligarewal22/32/10_2.png) [@rupaligarewal22](https://get-help.theconstruct.ai/u/rupaligarewal22)\
**Post date:** [February 7, 2022, 11:40am UTC](https://get-help.theconstruct.ai/t/clarification-on-the-content-of-c-for-robotics-basics/15293/12 "2022-02-07T11:40:01Z")

</div>

> [@Joseph1001](#):
>
> ```auto
> #ifndef ROSBOT_CLASS_H
> #define ROSBOT_CLASS_H
> 
> ```

[https://www.cprogramming.com/reference/preprocessor/ifndef.html](https://www.cprogramming.com/reference/preprocessor/ifndef.html)
