MQL4 Overload

Overview

Method overloading in MQL4 enables the definition of two or more methods within the same class that share the same name but differ in their number of parameters. This process is known as method overloading and is a mechanism for realizing polymorphism.

Resolution Rules

When an overloaded method is called, the MQL4 compiler follows a specific search order to find the most suitable function:

1. **Class Methods:** The compiler first searches for an exact match among the methods defined directly within the current class. 2. **Base Class Methods:** If no exact match is found in the current class, the compiler searches through the methods of the base classes, progressing sequentially from the nearest ancestor to the most distant one. 3. **Other Functions:** Finally, if no match is found in the class hierarchy, the compiler searches among other available functions.

Priority

  • If an exact match is found at any level, that method is used.
  • If no exact match exists across all levels, but multiple suitable functions are found at different levels, the function found at the *least* level (i.e., the most specific match, typically within the class itself or its immediate base) is selected.
  • Within a single level (e.g., within the current class), there cannot be more than one suitable overloaded function. If multiple functions with the same name and parameter types exist at the same level, it would result in an error.
  • Related Concepts

  • [Polymorphism](/basis/oop/polymorphism)
  • [Function Overloading](/basis/function/functionoverload)
  • [Virtual Functions](/basis/oop/virtual)