#include <string>
#include <iostream>
#include <vector>
using namespace std;
class Test {
public:
int testing() {
Test t;
return t.x;
}
private:
int x = 0;
};
int main() {
Test a;
cout << a.testing() << endl;
}
I did not know I can access the private data member x
of the t
(the instance of Test
that is not this
) within the class definition of the Test
. Why am I allowed to use t.x
in the example code?