是否可以在C ++ / CLI中定义通用接口中的covariancy / contravariancy? [英] Is it possible to define covariancy/contravariancy in generic interface in C++/CLI?

查看:80
本文介绍了是否可以在C ++ / CLI中定义通用接口中的covariancy / contravariancy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个很好的
关于C#中的covariancy和contravariancy的文章
。是否有可能在C ++ / CLI中实现这样的协变/逆变接口?

There is a nice article on covariancy and contravariancy in C#. Is it possible to implement such a covariant/contravariant interface in the C++/CLI?

    interface IMyGeneric<out T> { }
    interface IMyOtherGeneric<out T> { }

    class MyGeneric<T> : IMyGeneric<T> { }
    class MyOtherGeneric<T> : IMyOtherGeneric<T> { }

    void Foo(IMyGeneric<IMyOtherGeneric<string>> arg) { }

    void Bar()
    {
        var mgs = new MyGeneric<MyOtherGeneric<string>>();
        Foo(mgs);
    }




我怎么能,或者我可以在C ++ / CLI中实现它?


How can I, or can I at all, implement it in C++/CLI?

推荐答案

当然是。它完全相同。 C#和C ++ / CLI是非常相似的编程语言。当然,没有"外出"的C ++ / CLI中的operator。你必须创建一些库?或者你是从原生C ++ od
C到Managed .NET创建包装器?因为..没有理由使用这样的...生物..

yes of course. It is identical. The C# and C++/CLI are very similar programming languages. Of course, there is no "out" operator in C++/CLI. You have to create some library ? or are you creating wrapper from native C++ od C to Managed .NET ? Because .. there is no reason to use such ... creatures..

但是,......我很好奇,你正在使用C ++ / CLI,因为上一个完全稳定的版本在MS VS 2008 SP1中。从那以后,微软删除了IntelliSence,视觉设计师也停了下来。在MSVS 2013,15,17中情况并不好。

But, .... I am very curious, that you are using C++/CLI because last fully stable version was in MS VS 2008 SP1. Since then microsoft removed IntelliSence and the Visual designer stopped too. Situation is not better in MSVS 2013,15,17.

Jerry


这篇关于是否可以在C ++ / CLI中定义通用接口中的covariancy / contravariancy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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