如何能做到函數返回值重載?簡單的說
string Test() {
int Test() {
然後通過接受方的上下文自動選取重載
int i = Test();
string s = Test();
當然VB或者C#都是不允許這樣寫的
class Foo
{
string TestString()
{
return
}
int TestInt()
{
return
}
public TestHelper Test()
{
return new TestHelper(this);
}
public struct TestHelper
{
Foo m_host;
public TestHelper(Foo host)
{
m_host = host;
}
public static implicit operator int(TestHelper helper)
{
return helper
}
public static implicit operator string(TestHelper helper)
{
return helper
}
}
}
調用的語法非常之完美
Foo f = new Foo();
int i = f
string s = f
怎麼樣
From:http://tw.wingwit.com/Article/program/net/201311/13428.html