previous | start | next

2.1.1 Example (non-template)

The intArray class. intArray's grow automatically unlike ordinary arrays.

#ifndef INTARRAY_H
#define INTARRAY_H

#include <iostream>

using namespace std;


class intArray
{
  int *arr;
  int arr_size;
  int arr_capacity;
  void grow(int new_capacity);
public:
  intArray();
  intArray(int sz);
  intArray(const intArray& other); // 1. copy constructor

  int& at(int i);
  const int& at(int i) const;
  void add(int x);

  void operator=(const intArray& other); // 2. assignment

  int size() const;
  ~intArray();  // 3. destructor
};

#endif


previous | start | next