C ++ / CLI:是的返回类型超载只可能吗? [英] C++/CLI: Is overloading on return type only possible?

查看:153
本文介绍了C ++ / CLI:是的返回类型超载只可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的理解很好,在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

这篇关于C ++ / CLI:是的返回类型超载只可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆