S
shaun roe
Question about pointer-to-data members
I have a deeply nested loop, the innermost bit looks a little like this:
for(it(vec.begin(), end(vec.end()), it!=end;++it){
if (global == 0){
myObj = it->func().second->anObj();
} else {
myObj = it->func().first->anObj();
}
myVec.push_back(anObj);
}
where it->func() returns a pair of objects' pointers with 'anObj' functions which return an object
suitable for insertion in myVec.
Now, given that 'global' is known before I enter any loops, I could in principle decide to use the
'first' or 'second' before I ever enter this loop, instead of deciding inside the loop (and
hopefully thus save a few ns of time)... I thought to use a pointer-to-member (the member being
'first' or 'second') but cannot figure out the syntax.
This is what I am trying:
const primaryObj * pair<const primaryObj *, const primaryObj *>::*pFirstOrSecond;
pFirstOrSecond = global? (&pair<const primaryObj *,const primaryObj *>::first)pair<const
primaryObj *,const primaryObj *>::second);
the compiler complains :
.../src/SCTHitsNoiseMonTool.cxx: In member function `StatusCode
SCTHitsNoiseMonTool::generalHistsandNoise()':
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_pair.h:74: error:
object missing in reference to `std:air<const Trk:repRawData*, const Trk:repRawData*>::second'
where Trk:repRawData corresponds to 'primaryObj' in the example above, as if it is looking for the
concrete object rather than the generic pointer-to-member.
can anyone help?
cheers
shaun
I have a deeply nested loop, the innermost bit looks a little like this:
for(it(vec.begin(), end(vec.end()), it!=end;++it){
if (global == 0){
myObj = it->func().second->anObj();
} else {
myObj = it->func().first->anObj();
}
myVec.push_back(anObj);
}
where it->func() returns a pair of objects' pointers with 'anObj' functions which return an object
suitable for insertion in myVec.
Now, given that 'global' is known before I enter any loops, I could in principle decide to use the
'first' or 'second' before I ever enter this loop, instead of deciding inside the loop (and
hopefully thus save a few ns of time)... I thought to use a pointer-to-member (the member being
'first' or 'second') but cannot figure out the syntax.
This is what I am trying:
const primaryObj * pair<const primaryObj *, const primaryObj *>::*pFirstOrSecond;
pFirstOrSecond = global? (&pair<const primaryObj *,const primaryObj *>::first)pair<const
primaryObj *,const primaryObj *>::second);
the compiler complains :
.../src/SCTHitsNoiseMonTool.cxx: In member function `StatusCode
SCTHitsNoiseMonTool::generalHistsandNoise()':
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_pair.h:74: error:
object missing in reference to `std:air<const Trk:repRawData*, const Trk:repRawData*>::second'
where Trk:repRawData corresponds to 'primaryObj' in the example above, as if it is looking for the
concrete object rather than the generic pointer-to-member.
can anyone help?
cheers
shaun