member functions

Could any one help me with this please:

G4RunManager::GetRunManager()->SetRandomNumberStore(true);

where G4RunManager is a class name.


So GetRunManager() is a function in this class which poits to another function SetRandomNumberStore(true), am I right?

The thing that I don't understand is the meaning of a function pointing to another, does it mean that the second function should be a part of the first function?

Thank you in advance
No.

You must learn operators and operator precedence.


This G4RunManager::GetRunManager() function gets done first. It returns a pointer to the G4RunManager object.

as we now have a pointer to the run manager object, we use -> to call the SetRandomNumberStore
member function of the run manager object.

Last edited on
yes I am trying to learn. I have read that part several times. but still I am confused:(

is it right to say like this:
you mean that the result of function GetRunManager() is a pointer to an object of class

G4RunManager that points to another function of the class which is:
SetRandomNumberStore(true)

G4RunManager::GetRunManager()->SetRandomNumberStore(true);
is equivalent to:
1
2
G4RunManager* mgr = G4RunManager::GetRunManager();  // looks like a Singleton
mgr->SetRandomNumberStore(true); // invoke SetRandomNumberStore() method 
Last edited on
Aha thanks but is it the same case as :

G4RunManager::GetRunManager()->SetRandomNumberStore()->GetParticelDefinition()->GetParticleName();

I have added two more functions, is that still mgr who points to GetParticelDefinition() and GetParticleName()

Really thanks
only if SetRandomNumberStore() also returns G4RunManager*, which I seriously doubt

most likely it returns void, in which case, what you assume (in stringing those calls together) isn't valid

some languages, like Smalltalk, encourage you to return the original object so you can string calls together like that

C++, on the contrary, does not, except in special cases like ostream& operator<<( ostream& ), etc...
Last edited on
Sorry but I didn't understand again,

I typed you the real example:

G4String particel= kinematic->GetParticleGun()->GetParticleDefinition()->GetParticlename();

Could you please help me with this as well

Many thanks
You need to break that down into individual calls

1. what does GetParticleGun() return?
2. does it return an object? if so, does that object have a GetParticleDefinition() method?
3. if not, you cannot do this
4. if so, what does GetParticleDefinition return?
5. does it return an object? if so, does that object have a GetParticlename() method?
6. if not, you cannot do this
7. if so, you are ok if and only if the object returned is a G4String - otherwise, you can't assign it to particel (sic)

Topic archived. No new replies allowed.