“范型”总是让我联想到那几乎无所不能的C++ Template,可这C#的范型却让我抓狂。
C#中编译如下代码,
class A<T>
 {
        
public A()
        {
            
this.member1 = new T();
        }
        
private T member1;
 }
这代码看上去多自然啊,居然报错:
Cannot create an instance of the variable type 'T' because it does not have the new() constraint 

抓狂,不是说范型嘛,我还没说T是什么类型呢,编辑器就说does not have the new() constraint, 公然“强奸”我的意志,Bull shit。谁来拯救我这无知的人啊!


Posted on 2007-05-21 22:02  Nemo Wang  阅读(815)  评论(7编辑  收藏  举报
若不是耶和华建造房屋,建造的人就枉然劳力; 若不是耶和华看守城池,看守的人就枉然警醒。