Why do I have to preface function calls with Namespace::?

Hello,

I am using a ROOT installation on a new machine. I noticed that I have to code

->TH1::Fill

whereas I have always been able to use

->Fill

when making function calls from C++. Why does this happen, and how can I shortcut all of my function calls so that I don’t have to go through two thousand lines and add all the namespaces?

This is not true, you do not have to qualify the name (there are cases when you have to, but it’s not your case since you said “before” it worked with ->Fill). Please show a code snippet to reproduce what you think your problem is and also tell us your ROOT"s version (though CINT does not change for the last N years and cling is a full-blown C++ interpreter).

As I said, I changed to a new machine so the install is very different. The code is with and without the namespaces. If I don’t include them, I get errors during runtime.

I’m using 5.34.00

As I said, I changed to a new machine so the install is very different. The code is with and without the namespaces. If I don’t include them, I get errors during runtime.[/quote]

C++ syntax does not depend on your machine, it’s something … well known and fixed. It will be the same even if you work in the space on a special super-computer.
And TH1 is not a namespace name, it’s a class name.
Please, demonstrate the code reproducing your problem or have a look at C++ syntax (I believe you can find a grammar elsewhere easily). Also read about using a qualified name in a function call (this can suppress virtual function call).

I’m giving you an accurate report of what happened. I received errors until I added TF:: to my calls, at which point the program worked.

I’m giving you an accurate report of what happened.[/quote]

No, you are not. You call it a namespace name while it’s a class name. You say you have runtime errors without explaining exactly what are these error. You are not giving any actual details. I’ve asked you (twice) to give a minimal code demonstrating your problem, but still have no reply on this. And now you’re talking already about adding TF:: to your calls - what is this?

Since you can not provide any code, I’ll do this. The code below works perfectly without any qualified names:

TH1F * hist = new TH1F("a", "b", 100, -1., 1.);
hist->Fill(0);
TH2F * hist2d = new TH2F("c", "d", 100, -1., 1., 100, -1., 1.);
hist2d->Fill(0, 0);

Now, as you can not describe your problem, I have to use my non-existing psychics skills - are you trying to call Fill(x) on a 2 or 3 dimensional histogram?

If this is your case, then: it’s not a runtime error, it’s a compile time error - either interpreter or compiler tells you about an attempt to call a protected member function.

Probably, before it was public and it was noop for 2d/3d histogram:

Int_t Fill(Double_t) {return -1;} //MayNotUse //from TH2.h, something like ROOT 5.22

Int_t Fill(Double_t) {return -1;} //MayNotUse Int_t Fill(Double_t,Double_t) {return -1;} //MayNotUse //TH3.h, ROOT 5.22

If this is the behavior you considered to be correct, then it’s time to really fix your program, removing 1d fill from 2d/3d objects.