Function return different type according to the parameters.

nojoking kuangdong at gmail.com
Sun Sep 24 06:36:24 PDT 2006


How to return different types?For Example:

test.d
/++/
import std.stdio;

void main()
{
Test test;
test["a"]="A string. ";
test["b"]=1234;
test["c"]=true;

writefln(test["a"],test["b"],test["c"]);
}

struct Test
{
char[][char[]] strarr;
int[char[]] intarr;
bool[char[]] bolarr;

void opIndexAssign(int value,char[] key)
{
intarr[key]=value;
}
void opIndexAssign(char[] value,char[] key)
{
strarr[key]=value;
}
void opIndexAssign(bool value,char[] key)
{
bolarr[key]=value;
}
/+???????????????????
opIndex(char[] key)
{
}
???????????????????+/
}



More information about the Digitalmars-d-learn mailing list