Protected default constructor for ROOT classes


I’ve been attempting to migrate from ROOT-5 to ROOT-6, but am unable to compile a shared library with classes added that have protected default constructors. I see in the docs for ROOT-6 that a public default constructor is required, but in a number of cases these are singletons or have no public constructor for another reason (e.g. only static methods but some state information that means a class with no constructor is a sensible implementation). I can’t see any way around this in the docs, but was wondering whether there’s some way to retain the private/protected constructors?



You can keep the default constructor protected/private by adding an explicit I/O constructor:[code]
class TRootIOCtor; // Need to use this spelling and/or announce the alternative spelling to rootcling.

class MyClass {
MyClass(TRootIOCtor*) {};
};[/code]See TClass::New for more details.


Hi Philippe,

I saw this in the reference, I guess it wasn’t clear to me what the purpose of the IO constructor is so I didn’t want to implement it blindly without understanding a little better. It seems somewhat to get around classes where our implementation is a singleton (I know use of these is not necessarily good practice) we need to add in a public constructor - I guess we have to be explicit with our documentation that this is just there to compile the ROOT dictionary.