Can anybody share whats a member variable,

i couldnt really grasp the definition of member variable, classes, instances, in the tutorial, can anyone explain to me but in a fairly lament term as i am very new to coding. Thank you

  • Classes are just a way to define your own type.

  • Instances are just some area of memory that holds some value of some type e.g.

    int a = 10;
    

    Here a is an instance of an int and holds the value 10.

  • Member variables are variables that are a member of the class e.g.

    class Example
    {
        int Value = 10;
    };
    

    Here Value is a member variable of the Example class. So when you create an instance of that class e.g. Example E;, it will have its own Value member.

Further reading:

https://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/

1 Like

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

Privacy & Terms