Inheritance in Root

Hi everybody,

I’m new to Root and I haven’t used C++ for a few years, so sorry if my question turns out to be a stupid one.

I am trying to extend an existing ROOT class with some new capabilites. As far as I understand, when I am creating a descendant of an existing class, it should by default inhreit all its constructors.

For instance, this code

class Line2: public TLine
ClassDef(Line2,0) // Test class
};

should define a new class Line2 which has an access to all methods of it’s ancestor, TLine, including constructors. Isn’t that so?

Nevertheless, it doesn’t work. It compiles fine, but when I’m trying to declare an instance of Line2:

Line2 a(1.,2.,3.,4.)

I’m getting an error message:

Error: Can’t call Line2::Line2(1.,2.,3.,4.) in current scope FILE:(tmpfile) LINE:1
Possible candidates are…
filename line:size busy function type and name (in Line2)
(compiled) 0:0 0 public: Line2 Line2(void);
(compiled) 0:0 0 public: Line2 Line2(const Line2&);
filename line:size busy function type and name (in TLine)
filename line:size busy function type and name (in TObject)
filename line:size busy function type and name (in TAttLine)
*** Interpreter error recovered ***

Any help will be appreciated.

Hi Nikolay,

Your assumption is wrong. In your case, you must define :
Line2::Line2() {;} //dummy default constructor
Line2::Line2(double x1,double y1, double x2, double y2) : TLine(x1,x1,x2,y2)

Rene