C++ Neural Networks and Fuzzy Logic C++ Neural Networks and Fuzzy Logic
by Valluru B. Rao
M&T Books, IDG Books Worldwide, Inc.
ISBN: 1558515526   Pub Date: 06/01/95
  

Previous Table of Contents Next


Writing C++ Programs

Before one starts writing a C++ program for a particular problem, one has to have a clear picture of the various parameters and variables that would be part of the problem definition and/or its solution. In addition, it should be clear as to what manipulations need to be performed during the solution process. Then one carefully determines what classes are needed and what relationships they have to each other in a hierarchy of classes. Think about is-a and has-a relationships to see where classes need to defined, and which classes could be derived from others. It would be far more clear to the programmer at this point in the program plan what the data and function access specifications should be and so on. The typical compilation error messages a programmer to C++ may encounter are stating that a particular function or data is not a member of a particular class, or that it is not accessible to a class, or that a constructor was not available for a particular class. When function arguments at declaration and at the place the function is called do not match, either for number or for types or both, the compiler thinks of them as two different functions. The compiler does not find the definition and/or declaration of one of the two and has reason to complain. This type of error in one line of code may cause the compiler to alert you that several other errors are also present, perhaps some in terms of improper punctuation. In that case, remedying the fundamental error that was pointed out would straighten many of the other argued matters.

The following list contains a few additional particulars you need to keep in mind when writing C++ programs.

  A member x of an object A is referred to with A.x just as done with structure elements in C.
  If you declare a class B, then the constructor function is also named B. B has no return type. If this constructor takes, say, one argument of type integer, you define the constructor using the syntax: B::B(int){whatever the function does};
  If you declare a member function C of class B, where return type of C is, say, float and C takes two arguments, one of type float, and the other int, then you define C with the syntax: float B::C(float,int){whatever the function does};
  If you declare a member function D of class B, where D does not return any value and takes no arguments, you define D using the syntax: void B::D( ){whatever the function does};
  If G is a class derived from, say, class B previously mentioned, you declare G using the syntax: class G:B. The constructor for G is defined using the syntax: G::G(arguments of G):B(int){whatever the function does}. If, on the other hand, G is derived from, say, class B as well as class T, then you declare G using the syntax: class G:B,T.
  If one class is declared as derived from more than one other class, that is, if there are more than one base class for it, the derivations specification can be different or the same. Thus the class may be derived from one class publicly and at the same time from another class privately.
  If you have declared a global variable y external to a class B, and if you also have a data member y in the class B, you can use the external y with the reference symbol ::. Thus ::y refers to the global variable, whereas y, within a member function of B, or B.y refers to the data member of B. This way polymorphic functions can also be distinguished from each other.

This is by no means a comprehensive list of features, but more a brief list of important constructs in C++. You will see examples of C++ usage in later chapters.

Summary

A few highlights of the C++ language are presented.

  C++ is an object-oriented language with full compatibility with the C language.
  You create classes in C++ that encapsulate data and functions that operate on the data, and hiding data where a public interface is not needed.
  You can create hierarchies of classes with the facility of inheritance. Polymorphism is a feature that allows you to apply a function to a task according to the object the function is operating on.
  Another feature in C++ is overloading of operators, which allows you to create new functionality for existing operators in a different context.
  Overall, C++ is a powerful language fitting the object-oriented paradigm that enables software reuse and enhanced reliability.


Previous Table of Contents Next

Copyright © IDG Books Worldwide, Inc.