Problem loading class at RunTime

Hi,

Unfortunately I am force to use an old version of ROOT (6.02.12) which seems not to have support for R__LOAD_LIBRARY which is the trick I am using in more recent releases to load a class. What am I supposed to use in that old version?

The use case is the following as it works on newer releases:
MyClass.h

//This is MyClass.h
class MyClass {
public:
  MyClass();
  int GetFoo() const {return foo;}
protected:
  int foo;
};

MyClass.C

//This is MyClass.C
#pragma once

#include "MyClass.h"

MyClass::MyClass():foo(0) {}

MyExample.C

// This is MyExample.C
R__LOAD_LIBRARY(MyClass.C+)

void MyExample() {

  MyClass* mc = new MyClass();

  cout << "Foo = " << mc->GetFoo() << endl;
}

To execute it it is enough to ‘.x MyExample.C’ on a newer ROOT. It doesn’t work on older releases.

Thanks a log for your help!

Isidro

Maybe something like this:

// This is MyExample.C
//R__LOAD_LIBRARY(MyClass.C+)
#include "MyClass.C"

void MyExample() {

//  gROOT->LoadMacro("MyClass.C+");

  MyClass* mc = new MyClass();

  cout << "Foo = " << mc->GetFoo() << endl;
}

Thanks Bertrand,

That surely works though not the nicest way to do it. I will survive with it :slight_smile: It is funny this ROOT version is in between what worked for ROOT 5 and what is now the supposed way to do the things.

Cheers,

Isidro

You can also use

#include "MyClass.C+"

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.