类调用的问题(60)

  • 主题发起人 主题发起人 yufeiguan
  • 开始时间 开始时间
Y

yufeiguan

Unregistered / Unconfirmed
GUEST, unregistred user!
unit U_bst;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,u_weak;type Boosting = class private { Private declarations } n_samples:integer; //number of train sample n_input:integer; //dimension of each sample max_iter:integer; //max number of boost step leaner:array of WeakLearner; //all weaker leaner //train Boosting 1 vs 1 function TrainOneVsOne(trainmatrix:array of double;label1,label2:double):WeakLearner; public { Public declarations } procedure DoTrain(); end;implementationfunction Boosting.TrainOneVsOne(trainmatrix:array of double;label1,label2:double):WeakLearner;var wk:WeakLearner;begin wk.Init(max_iter,label1,label2); wk.free;end;procedure Boosting.DoTrain();var train:array of double;beginsetlength(leaner,1);leaner[0]:=TrainOneVsOne(train,-1,+1);leaner[0].Free;end;end.//上面单元包含一个boosting 类。unit U_weak;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;type WeakLearner = class private { Private declarations } maxnum:integer; // + label positive_label:double; // - label negative_label:double; public { Public declarations } procedure Init(num:integer;label1,label2:double); end;implementationprocedure WeakLearner.Init(num:integer;label1,label2:double);begin maxnum := num; positive_label := label1; negative_label := label2; // decisionstump := new DecisionStump[num]; //alpha = new double[num];end;end.//上面单元包含一个WeakLearner类。procedure TForm1.Button1Click(Sender: TObject);var bst:boosting;begin bst.DoTrain; bst.Free;end;//以上是调用boosting类。问题如下:boosting类的私有函数TrainOneVsOne调用WeakLearner类的init函数一直出错。请达人指点。谢谢!
 
楼主真牛啊,定义类,不加T打头,类使用时,不创建,就直接使用.var bst:boosting;begin bst.DoTrain; bst.Free;end;起码得创建一下再用吧.bst := boosting.create;
 
接受答案了.
 
后退
顶部