Dear Rooters
I have a question how to SetBranchAddress() using the following inherited classes.
class MyClass //as base class
class MyClassA: public MyClass
class MyClassB: public MyClassA
class MyClassC: public MyClassB
When doing the following:
MyClass *myclass = 0;
if (strcmp(Class, "MyClassC") == 0) {
tree->SetBranchAddress("MyBranch", &((MyClassC*)myclass));
} else if (strcmp(Class, "MyClassB") == 0) {
tree->SetBranchAddress("MyBranch", &((MyClassB*)myclass));
} else {
tree->SetBranchAddress("MyBranch", &((MyClassA*)myclass));
}
for (Int_t i=0; i<entries; i++) {
tree->GetEntry(i);
arr[i] = myclass->GetData();
}
I get the following compiler warning:
"warning: argument to ‘&’ not really an lvalue; this will be a hard error in the future"
although the program works fine.
However, when I do the following:
MyClass *myclass = 0;
if (strcmp(Class, "MyClassC") == 0) {
myclass = ((MyClassC*)myclass);
tree->SetBranchAddress("MyBranch", &myclass);
} else if (strcmp(Class, "MyClassB") == 0) {
myclass = ((MyClassB*)myclass);
tree->SetBranchAddress("MyBranch", &myclass);
} else {
myclass = ((MyClassA*)myclass);
tree->SetBranchAddress("MyBranch", &myclass);
}
for (Int_t i=0; i<entries; i++) {
tree->GetEntry(i);
arr[i] = myclass->GetData();
}
everything is fine w/o compiler warning.
What is the difference, and is there a better way?
Thank you in advance.
Best regards
Christian