简体   繁体   中英

#pragma link for template function

I use cling and would like to see my templates function into environment, so after loading (.L) of my class I want to be able to call my template function.

I can do this for such template:

template <typename T>
    static void ObjectApplyStyle(const char* styleName, T *cObj, Int_t objNum=0, Int_t verbose=0);

For such function I added in my LinkDef.h file next strings:

#pragma link C++ function AliDrawStyle::ObjectApplyStyle(const char*, TGraph *, Int_t, Int_t);
#pragma link C++ function AliDrawStyle::ObjectApplyStyle(const char*, TH1 *, Int_t, Int_t);
#pragma link C++ function AliDrawStyle::ObjectApplyStyle(const char*, TF1 *, Int_t, Int_t);

So my question is how I can do the same, but for such template function?

  template <typename T>
    static T PrepareValue(const char* styleName, TString propertyName, TString elementID, TString classID, TString objectID, TString localStyle, Bool_t &status, Int_t objNum=0, Int_t verbose=0);

If I will add this string in LinkDef.h:

#pragma link C++ function <Int_t> AliDrawStyle::PrepareValue(const char*, TString, TString, TString, TString, TString, Bool_t &, Int_t, Int_t);
#pragma link C++ function <Float_t> AliDrawStyle::PrepareValue(const char*, TString, TString, TString, TString, TString, Bool_t &, Int_t, Int_t);

compiler give me warning "func not found".

As you can see here the difference between my templates functions - the first contain T type in arguments, but the second has the same arguments list and has a different type of returned value.

Do you have any idea?

In Addition to discussion with Axel:

Let's see to examples:

MyClass.h

class MyClass {

    public:
        template <typename T>
            static T Ex1();
        template <typename T>
            static T Ex2();

};

MyClass.cxx

#include "MyClass.h"

template <typename T>
    T MyClass::Ex1(){

}

template <typename T>
    T MyClass::Ex2(){
}

And this what I see in root6:

root [0] #include "MyClass.h"
root [1] MyClass::
MyClass
operator=
~MyClass
root [1] MyClass::

And the same for .L

root [0] .L MyClass.cxx+ 
root [1] MyClass::
MyClass
operator=
~MyClass
root [1] MyClass::

But if I add explicit calling for one function: MyClass.cxx

#include "MyClass.h"

template <typename T>
    T MyClass::Ex1(){
      // here I added calling of template function
      MyClass::Ex2<float>();

}

template <typename T>
    T MyClass::Ex2(){
}

I will start to see:

root [0] .L MyClass.cxx+ 
root [1] MyClass::
Ex2<float>
MyClass
operator=
~MyClass
root [1] .q

But if I will use only include I can't see my function anycase:

root [0] #include "MyClass.h"
root [1] MyClass::
MyClass
operator=
~MyClass

Thanks!

No need for adding your function to a LinkDef.h. Just #include the header (or .L your class) and call it! If that fails please post the error message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM