CLASS in DM and C++ - Practical Electron Microscopy and Database - - An Online Book - |
||||||||||||||||||||||
Microanalysis | EM Book http://www.globalsino.com/EM/ | ||||||||||||||||||||||
================================================================================= | ||||||||||||||||||||||
CLASS is the foundation of C++'s support for object-oriented programming, and is at the core of many of its advanced features. The class is C++'s basic unit of encapsulation and provides the mechanism by which objects are created. A class defines a new data type, which specifies the form of an object. A class actually includes both data and the code that will operate on that data. Therefore, a class links data with code. A class specification is used to construct objects. In other words, objects are instances of a class, and thus a class is essentially a set of plans that specify how to build an object. When a class is defined, you declare the data that it contains and the code that operates on that data. Even though very simple classes might contain only code or only data, most real-world classes contain both. Within a class, the data is contained in variables and code is contained in functions. Collectively, the functions and variables, which constitute a class, are called members of the class. Therefore, a variable declared within a class is called a member variable, and then a function declared within a class is called a member function. In C++, a class can contain private as well as public members. By default, all items defined in
a class are private. However, in DM, a class can only contain private members. The general
form of a class declaration in C++ is, A class is created by using the keyword class, for instance, shown in Table 1110a. Note the general form of class declaration in DM, shown in Table 1110a, is very different from the one for C++ mentioned above. If the script is run from a script window, and the script declares a class, then that class will only be usable during execution of that script. The class remains available as long as any object created from that class exists, or until the class is explicitly unloaded. In general, if a class is needed outside of the script, then the class should be installed as libraries by "Installing a script library". Furthermore, Passing-Objects-to-Functions can be used in CLASS. In this case, an object can be passed to a function in the same way as any other data type, namely a copy of the object, not the actual object itself, is passed to the function. This copy becomes the parameter in the function, so that a new object comes into existence. When the function terminates, the copy of the argument as well as the parameter is destroyed. An example of Passing-Objects-to-Functions can been seen in Table 1110a. Table 1110a. Examples of CLASS in DM.
Table 1110b presents some common mistakes in scripts so that the execution of the scripts are failed. Table 1110b. Failed examples of CLASS in DM.
|
||||||||||||||||||||||
================================================================================= | ||||||||||||||||||||||
|
||||||||||||||||||||||