www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Two interpretations

reply JG <JG somewhere.com> writes:
Is it specified somewhere which way the following program will be 
interpreted?

     import std;

     struct A
     {
         int x=17;
     }

     int x(A a)
     {
         return 100*a.x;
     }

     void main()
     {
         A a;
        writeln(a.x);
     }
Jun 11 2021
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Fri, Jun 11, 2021 at 03:00:00PM +0000, JG via Digitalmars-d-learn wrote:
 Is it specified somewhere which way the following program will be
 interpreted?
 
     import std;
 
     struct A
     {
         int x=17;
     }
 
     int x(A a)
     {
         return 100*a.x;
     }
 
     void main()
     {
         A a;
        writeln(a.x);
     }
The rule is that member functions will always take precedence over UFCS. UFCS only kicks in when the member function of that name cannot be found. T -- For every argument for something, there is always an equal and opposite argument against it. Debates don't give answers, only wounded or inflated egos.
Jun 11 2021