Hi folks,

i have this struct:

import std.stdio, std.string;

struct Value {

        private long intVal;
        private bool boolVal;
        private string type;

        Value opAssign(long val) {
                intVal = val;
                
                if(val == 0) {
                        boolVal = false;
                } else {
                        boolVal = true;
                }

                type = "LONG";
                
                return this;
        }

    Value opAssign(bool val) {
                if(val) {
                        boolVal = true;
                        intVal = 1;
                } else {
                        boolVal = false;
                        intVal = 0;
                }
        
                type = "BOOL";
                
                return this;
        }

        string getType() {
                return type;
        }

}

int main() {
    Value data;
        data = 1;
        
        writeln(data);
        writeln(data.getType());

        assert(data.getType() == "LONG");
        
        return 0;
}

output:
Value(1, true, "BOOL")
BOOL


Can anyone tell me why the compiler call opAssign(bool val) and not opAssign(long val). I am passing an long value not a bool one.

Thanks,
Bogdan

Reply via email to