previous up next print clean
Next: Using basic member functions Up: AN IGF90 TUTORIAL Previous: AN IGF90 TUTORIAL

Constructing IGF90 objects

The first thing we need to know about an IGF90 object is how to create one. A class object is initialized by the initialization of its data members. C++ supports an automatic mechanism for the initialization of class objects. A special class member function, called a constructor, is invoked implicitely by the compiler whenever a class object is defined. Constructor functions are characterized by having the same name as of its class. There are several syntactical rules by which an IGF90 constructor can be called:

Note that in the first two examples, data1 and data2 are SEPlib90 data structures with a regular geometry. In the last example, the sintax data3.Space() returns a reference to the vector space of data3. Space() is a member function of the IGF90 class. The IGF90 data5 is then constructed with the same geometry as data3.

For many programs, all objects are allocated in the heap and referenced through pointers. The new operator allocates new dynamic memory. The delete operator takes a pointer to an object and reclaims its memory. Because of memory constraints, we will typically want to allocate IGF90 objects dynamically, and deallocate them as soon as we have finished using them.

  IGF90 * data5;     // A pointer to an IGF90 object.

  data5 = new IGF90 ("input");  // allocate dynamically and invoke
		                // the constructor

  ...
  delete data5;      // invoke the destructor and reclaim the mem


previous up next print clean
Next: Using basic member functions Up: AN IGF90 TUTORIAL Previous: AN IGF90 TUTORIAL
Stanford Exploration Project
11/11/1997