OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Instantiating classes

To use a class, you must create an instance of it.

You can instantiate a class in a number of ways:

  • Use the standard declaration syntax. This is the same syntax you use to declare any standard variable such as an int or char. In this example, app is initialized by calling the TMyApplication constructor with no arguments: TMyApplication app; You can use this syntax only when the class has a default constructor or a constructor in which all the parameters have default values.
  • Use the standard declaration syntax along with arguments to call a particular constructor. In this example, app is initialized by calling the TMyApplication constructor with a char * argument:
    TMyApplication app("AppName");
  • Use the new operator to allocate space for and instantiate an object. For example:
  • Use the new operator with arguments. In this example, app is initialized by calling the TMyApplication constructor with a char * argument:
    TMyApplication* app = new TMyApplication("AppName");
    The constructors call the base class constructors and initialize any needed data members. You can only instantiate classes that aren't abstract; that is, classes that don't contain a pure virtual function.