# Code in Unit 6.2 section will not compile due to x\_position being private

**URL:** <https://get-help.theconstruct.ai/t/code-in-unit-6-2-section-will-not-compile-due-to-x-position-being-private/42843>\
**Category:** C++ For Robotics\
**Tags:** error\
**Created:** [October 8, 2026, 6:14am UTC](https://get-help.theconstruct.ai/t/code-in-unit-6-2-section-will-not-compile-due-to-x-position-being-private/42843 "2026-10-08T06:14:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaf1096](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/z/71e660/32.png) [@zaf1096](https://get-help.theconstruct.ai/u/zaf1096)\
**Post date:** [October 8, 2026, 6:14am UTC](https://get-help.theconstruct.ai/t/code-in-unit-6-2-section-will-not-compile-due-to-x-position-being-private/42843/1 "2026-10-08T06:14:17Z")

</div>

```
Code below from section "Accessing attributes and methods: the dot ." in Unit 6.2 needs one change. first_robot.x_position should be changed to first_robot.set_position(1.15) so that a method reaches the private member x_position;

   Robot first_robot;

first_robot.name = "Fastbot"; // set an attribute
first_robot.x_position = 1.15;
first_robot.battery = 90;

first_robot.print_name(); // call a method

```

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [October 13, 2026, 6:14am UTC](https://get-help.theconstruct.ai/t/code-in-unit-6-2-section-will-not-compile-due-to-x-position-being-private/42843/2 "2026-10-13T06:14:28Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![bayodesegun](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/bayodesegun/32/10684_2.png) [@bayodesegun](https://get-help.theconstruct.ai/u/bayodesegun)\
**Post date:** [October 13, 2026, 1:13pm UTC](https://get-help.theconstruct.ai/t/code-in-unit-6-2-section-will-not-compile-due-to-x-position-being-private/42843/3 "2026-10-13T13:13:45Z")

</div>



---

<div class="post-metadata">

**Author:** ![takavarasha](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/takavarasha/32/7098_2.png) [@takavarasha](https://get-help.theconstruct.ai/u/takavarasha)\
**Post date:** [October 13, 2026, 1:54pm UTC](https://get-help.theconstruct.ai/t/code-in-unit-6-2-section-will-not-compile-due-to-x-position-being-private/42843/4 "2026-10-13T13:54:27Z")

</div>

Hi @zaf1096 , you need to make std::string name; public as shown in the most recent version of class Robot just before the “Accessing attributes and methods…” I suspect that you may have forgot to add the “public” keyword before declaring the member variables.
