On Thursday, 23 April 2015 at 09:48:21 UTC, Dennis Ritchie wrote:
Hi,
Why the program can not return different types of data from the conditional operator?

-----
import std.stdio;

auto foo() {

        if (true) {
                return 0;
        } else
                return "true";
}

void main() {

        writeln(foo);
}

Because 0 is an int and "true" is a string.
They're totally different types, and in a statically typed language like D, that just wont work.

Reply via email to