或许可以换种思路,用反射..class A
{
public static void Method()
{
Console.WriteLine("A.Method");
}
}
class B
{
private Type type;
public B(Type t)
{
this.type = t;
}
public void Method()
{
type.InvokeMember("Method", BindingFlags.InvokeMethod, null, null, new object[] { });
}
}调用:
B b = new B(typeof(A));
b.Method();
{
public static void Method()
{
Console.WriteLine("A.Method");
}
}
class B
{
private Type type;
public B(Type t)
{
this.type = t;
}
public void Method()
{
type.InvokeMember("Method", BindingFlags.InvokeMethod, null, null, new object[] { });
}
}调用:
B b = new B(typeof(A));
b.Method();
class A
{
public static Method(){ }
}class B
{
private A m_a;
public B(A a)
{
m_a = a;
}
public Method()
{
m_a.Method();
}
}B b = new B(A);
b.Method();
如果是在C++里边,可以考虑模版偏特化。不过标准C++是不支持函数的模版偏特化的。