Now we can create a simple class that has both a data member field and a member function:
class MyClass { int x; void printx() { std::cout << "The value of x is:" << x; } };
This class has one data field of type int called x, and it has a member function called printx()
.
This member function reads the value of x and prints it out.
This example is an introduction to member access specifiers or class member visibility.