opCast cannot implicitly convert a.opCast of type X to Y

aliak something at something.com
Tue Feb 13 20:35:57 UTC 2018


On Tuesday, 13 February 2018 at 12:12:30 UTC, Nathan S. wrote:
> On Monday, 12 February 2018 at 02:05:16 UTC, aliak wrote:
>> struct B(T) {
>>     T t;
>> }
>>
>> struct A(T) {
>>     T t;
>>     auto opCast(U)() {
>>         return B!U(cast(U)t);
>>     }
>> }
>>
>> void main() {
>>     auto a = A!int(3);
>>     auto b = cast(float)a; // error
>> }
>
> Having the result of "cast(float) a" not be a float would be 
> evil.

Ya :p dunno what I was thinking.


More information about the Digitalmars-d-learn mailing list