Jump to content

C++ Programming/Examples/Using A Class

From Wikibooks, open books for an open world
// very simple C++ program using a class.

#include <iostream>

class myClass
{
public:
 myClass(int);

private:
 int i;
};

myClass::myClass(int x) : i(x) {}

int main()
{
  myClass my_class(5);

  // dynamic
  myClass* my_class_ptr = new myClass(5);
  delete my_class_ptr;

  return 0;
}