TPad Copy Constructor?

Hello Everyone!

I would like to use a copy constructor of the TPad a la

import ROOT 
class Pad(ROOT.TPad):
    def __init__(self,pad = None):
    	if not pad is None:
        	ROOT.TPad.__init__(self, pad) #This is not possible
        else:
            	ROOT.TPad.__init__(self)
            	
canvas = ROOT.TCanvas()
canvas.Divide(2,2)
P = Pad(canvas.cd(2))

This is not possible as i see in the documentation says, there is no Copy constructor for TPad, other than for every other ROOT object i know. Is there any clever workaround?

Cheers and thanks,
Daniel

Daniel,

per TPad itself: TPad(const TPad &pad); // cannot copy pads, use TObject::Clone()
HTH,
Wim

Hi Wim,

Could you give an example, how this works? I need to inherit from TPad. I don’t want to only copy the pad. I want to add methods to an inherited object. Is there a possibility like

import ROOT
class Pad(ROOT.TPad):
    def __init__(self,pad = None):
        ROOT.TPad.__init__(self)
       	if not pad is None:
           	self = pad.Clone()	#How to make this right? This is nonesense of course

Cheers,

Daniel

No indeed, you can’t do that (see the TPad doc quoted above).

Your example code tries to pass a TCanvas onto a TPad copy ctor. That can never work even with a copy ctor, as it slices the object.

What’s the goal here? You don’t need inheritance just to add methods.

-Dom