C ++ / CLI:是的返回类型超载只可能吗?是的、类型、CLI

2023-09-04 04:55:57 作者:虚伪

如果我的理解很好,在C#中,这是可以做到的。

If I understand well, in C#, it is possible to do

public class X : ICloneable
{
    public X Clone() { ... }
    object ICloneable.Clone() { return Clone(); } // This calls the above
}

根据这个线程。这种过载是被禁止的在C ++中,因为它仅依赖于返回类型。

according to this thread. This kind of overloading is forbidden in C++, since it only depends on the return type.

现在,我愿做 ICloneable 这个确切的事情在C ++ / CLI。有什么办法?

Now, I would like to do this exact thing with ICloneable in C++/CLI. Is there a way ?

推荐答案

这类型的重载允许在C#中不同的返回类型,不是因为而是因为明确实现的接口 - ICloneable.Clone

This type of overloading is allowed in C# not because of different return type, but because of explicit implementation of interface - ICloneable.Clone.

关于C ++ / CLI看这里: HTTP:/ /msdn.microsoft.com/en-us/library/ms235235%28VS.80%29.aspx

About C++/CLI look here: http://msdn.microsoft.com/en-us/library/ms235235%28VS.80%29.aspx