-3

Just for example

Class A{
    public: 
    int a;    
};

int main(){
    A test;
    int b = test.a;
    int c = test.a();  
}

My question is that when accessing the member variable of a class, is there any difference between using test.a and test.a()?

Eiko
  • 25,601
  • 15
  • 56
  • 71

2 Answers2

2

Here test.a() is a call to a function whereas test.a is access to your object's public variable, both are different things.

Also, your syntax is incorrect it should be class instead of Class.

ani627
  • 5,578
  • 8
  • 39
  • 45
0

There is a big difference. test.a works, test.a() doesn't.

test.a() is a function call, a in class A is not a function.

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175