代码之家  ›  专栏  ›  技术社区  ›  Zen

c++0x概念和c#约束之间有什么区别?

  •  5
  • Zen  · 技术社区  · 17 年前

    概念 It specifies the properties required of a type .

    让你具体说明一下 约束条件 where “第条。

    非常感谢。

    1 回复  |  直到 14 年前
        1
  •  9
  •   Community Mohan Dere    9 年前

    要记住的一点是C++模板和C语言泛型不完全相同。看到这个了吗 answer

    从链接到解释C++ 0x概念的页面中,听起来好像是C++中希望指定模板类型实现某些属性。在C#中,约束比这更进一步,并强制泛型类型为该约束的“of”。例如,以下C#代码:

    public GenericList<T> where T : IDisposable
    

    表示任何用于代替T的类型 必须

    public abstract class ABC {}
    public class XYZ : ABC {}
    
    public GenericList<T> where T : ABC
    

    C++0x概念的想法只是说,用于代替T的类型必须具有ABC(或IDisposable)定义的相同属性,而不是它必须是该类型。