TClass::GetClass("MyClassName)->New() Fails


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: 6.36.02
Platform: macosx64
Compiler: Not Provided


Hello…

I have used the following code for a while:

TClass *taskClass = TClass::GetClass(taskClassName);
**if** (!taskClass)
   **throw** Exception();
Task * task = **static_cast**<Task*>(taskClass->New());

This usually works great! It enables me to create jobs based on a workflow file… But today I added a new class that inherits from my class Task. And I get the following message

Error in <TClass::New>: cannot create object of class CAP::ThermalModelTask
*** Break *** segmentation violation
\[/usr/lib/system/libsystem_platform.dylib\] \_sigtramp (no debug info)
\[/usr/local/Cellar/root/6.36.02/lib/root/libCling.so\] cling::TransactionPool::releaseTransaction(cling::Transaction\*, bool) (no debug info)\[/Users/aa7526/Documents/GitHub/CAP8.0/build/CAP\] main (no debug info)
\[/usr/lib/dyld\] start (no debug info)

The new class has a default constructor (with no argument), a copy constructor, as well as a virtual DTOR. It is defined in my own namespace CAP. The only difference is that this new class is a different folder and library built with cmake. But my other classes are all built that way. Is there a way to have a more verbose output that might identify why the instantiation fails?

As always, thanks in advance!!

Claude

There is no embedded extra output but you can add the following diagnosis code:

TClass *taskClass = TClass::GetClass(taskClassName);
if (!taskClass)
   throw Exception();
if (!taskClass->IsLoaded())
    std::cerr << "Debug: the TClass for " << taskClass->GetName() << " is not marked as loaded.  It's state is: << taskClass->GetState() << '\n';
if (!taskClass->GetNew())
    std::cerr << "Debug: the TClass for " << taskClass->GetName() << " does not have the accelerator function/wrapper for the constructor\n";
Task * task = **static_cast**<Task*>(taskClass->New());

Hi Philip

Thanks for the suggestion. I tried it and the accelerator function/wrapper is not available. Yet, I am defining that class like the others. Any thoughts?

Thanks again.

Is the TClass marked as loaded or not?

Yes. The class is marked as loaded. But the “new” operator is not available.

Ok. So somehow, rootcling thinks that the class can not be instantiated, common cause are:

  • the class is abstract (one of the abstract virtual function is not overloaded/implemented).
  • the default constructor is not public

Do you have a link to the header file for that class?

Brilliant! The “public:” keyword was missing. Thank you so very much!!!

Claude