class MyClass { private: int value; public: void setValue(int n); void printValue(); }; #include <stdio.h> int main() { /* Sample program demonstrating two ways to refer to class members */ /* direct declaration of instance of MyClass */ MyClass a; /* declaration of a pointer to instance of MyClass */ MyClass* b_ptr; /* creation (allocation) of instance pointed to by b_ptr */ b_ptr=new MyClass; /* initialization of values in both instances: */ a.setValue(12); /* using "period" syntax, since 'a' is an instance */ b_ptr->setValue(9); /* using "arrow" syntax, since 'b_ptr' is a pointer */ /* printing values from both instances: */ a.printValue(); b_ptr->printValue(); return (0); } /* Implementation of functions of class A */ void MyClass::setValue(int n) { value=n; } void MyClass::printValue() { printf("value=%d\n",value); }