Private members of the class are not accessible by object or function outside the class. Only functions inside the class can access them or friend functions. However, pointers can be used to access private data members outside the class.
The sample code is as follows:
#include <iostream>
using namespace std;
class sample_test{
private:
int n;
public:
sample_test() { n = 45; }
int display() {
return n;
}
};