Troubles Understanding Variables in Classes

Hi, I'm relatively new to C++ programming, and currently struggling to understand use of some functions. At the moment, I've been using this tutorial for help:
https://www.youtube.com/watch?v=jTS7JTud1qQ&list=PLAE85DE8440AA6B83&index=13

From what I understand in the proper way, we need to create this path in order to be able to use the variable in private, but I just can't wrap my head around how the public functions work and why they're needed. I just can't connect the dots as to how they make it possible for the code in main to get to the variable. Can somebody please help me?
1
2
3
4
5
6
7
class what{
  int x;
  public:
     int getx(){
        return x;
     }
}

The function here is public so you have an acess to it from main and it return x the private var, but the function is also a part of "what" so it possible to function to get a private variable inside the class
Last edited on
Topic archived. No new replies allowed.