문제

How do I create a strongly types alias in D? Something like:

alias euro = uint;
alias dollar = uint;

euro toEur(dollar pd) { ... }
dollar toDollar(euro pe) { ... }
도움이 되었습니까?

해결책

A strongly typed alias is actually a new type, so just use a plain struct:

struct euro {
     uint amount;
}

If you want it to implicitly convert to and from uint, you can also add alias amount this;, but that weakens the typing so you might not want to.

다른 팁

What you need is Typedef, which basically does what Adam suggests.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top