| AngelScript |

Loading...
Searching...
No Matches
Auto declarations

It is possible to use 'auto' as the data type of an assignment-style variable declaration.

The appropriate type for the variable(s) will be automatically determined.

      auto i = 18;         // i will be an integer
      auto f = 18 + 5.f;   // the type of f resolves to float
      auto o = getLongObjectTypeNameById(id); // avoids redundancy for long type names

Auto can be qualified with const to force a constant value:

      const auto i = 2;  // i will be typed as 'const int'

For types that support handles, auto will always become a handle as it is more efficient than doing a value assignment. If the variable must not be a handle for some reason, then do not use the 'auto' keyword.

      auto  a = getObject();  // auto is typed 'obj@'
      auto@ b = getObject();  // this is still allowed if you want to be more explicit

Auto handles can not be used to declare class members, since their resolution is dependent on the constructor.