Constructors not working

Svyat giraffe.sleep at yandex.ru
Fri Sep 2 18:35:22 UTC 2022


I write this code in one directory:

module time;

     struct Time {
         public int hours, minutes, seconds;
         this(int h, int m, int s) {
             hours = h;
             minutes = m;
             seconds = s;
         }
         Time opBinary(string op : "=")(int secos) {
             assert(secos <= 86_400);
             return new Time(secos / 3600, (secos % 3600) / 60, 
secos % 60);
         }
     }

module testfortime;
import time;
import std.stdio;

     void main() {
         Time time = 360;
         write(time.hours);
         readln;
     }


After execute 'dmd -run ./testfortime.d' i got this:
".\testfortime.d(6): Error: constructor `time.Time.this(int h, 
int m, int s)` is not callable using argument types `(int)`
.\testfortime.d(6):        too few arguments, expected `3`, got 
`1`"

WTF? Why standart constructor isn`t callable? How it`s possible 
in a programming language?


More information about the Digitalmars-d-learn mailing list