Bracket after C ++ variable name

Working with the source code below (this is open source), and I did not see parentheses after the variable name. UDefEnergyH is definitely a variable, as can be seen from line 1. Can someone tell me what these brackets do? I don’t know how to do this on Google. Thanks.

bins[0] = UDefEnergyH.GetLowEdgeEnergy(size_t(0)); vals[0] = UDefEnergyH(size_t(0)); //Don't know what this does??? sum = vals[0]; for (ii = 1; ii < maxbin; ii++) { bins[ii] = UDefEnergyH.GetLowEdgeEnergy(size_t(ii)); vals[ii] = UDefEnergyH(size_t(ii)) + vals[ii - 1]; sum = sum + UDefEnergyH(size_t(ii)); } 

And it is listed here in the header file:

 G4PhysicsOrderedFreeVector UDefEnergyH; 
+8
c ++ syntax
source share
3 answers

It looks like operator() overloaded for tyupe UDefEnerfyH .

One way to do this is to solve

 #include <iostream> using namespace std; struct MJ { void GetLowEdgeEnergy(size_t arg) { cout << "GetLowEdgeEnergy, arg = " << arg << endl; } void operator ()(size_t arg) { cout << "operator (), arg = " << arg << endl; } }; int main() { MJ UDefEnergyH; UDefEnergyH.GetLowEdgeEnergy(42); UDefEnergyH(42); return 0; } 
+7
source share

You seem to mean a field in the G4SPSEneDistribution class. Its type is G4PhysicsOrderedFreeVector . And look here here . As you can see, operator () is overloaded and, apparently, this is what is called on the second line. It is not very easy to find out what it does, but if you look at the comment in the header file for G4PhysicsVector , you will see

 00100 // Returns simply the value in the bin specified by 'binNumber' 00101 // of the dataVector. The boundary check will not be Done. If 00102 // you want this check, use the operator []. 
+1
source share

This is what is called direct initialization, in which it first constructs an object with "0" as an immediate parameter, and then assigns it to the first index of the vals array.

0
source share

All Articles