Order of lookup |
Top Previous Next |
What is translated > Types > Order of lookup
The order by which symbols are looked up is different in Delphi and C++. Delphi tries to find a symbol in the last used unit at first and if it isn't there Delphi will continue with the previous used unit. If both used units contain the same symbol, but defined differently, this doesn't matter, because Delphi will take just the definition, that it finds first. In the following example MyType will be a pointer to an integer:
uses aunit, // PType = ^TestRecord; bunit; // PType = ^Integer;
Type MyType = PType;
In C++ however both definitions of PType will be looked up and the code will not compile, because of the ambiguity. Even worse, if for example bunit would include cunit with another definition of PType, C++ would lookup this definition too. In C++ therefore the ambiguity has to be resolved with the correct namespace:
#include "aunit.h" // PType = ^TestRecord; #include "bunit.h" // PType = ^Integer;
typedef bunit::PType MyType;
Delphi2Cpp inserts the correct scope expression automatically.
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |