Hi roottalk,
with the latest ROOT (from CVS this morning) on RH 7.3 with gcc 3.2 I am
having trouble with the generated dictionary method ShowMembers when
the class has a const data member. The problem is that ShowMembers
is a non-const function (why?) and to examine the const member it
calls its ShowMembers function. In the simple example below fB is a
const
member function but the generated code is:-
//______________________________________________________________________
________
void A::ShowMembers(TMemberInspector &R__insp, char *R__parent)
{
// Inspect the data members of an object of class A.
--
if (R__ncp || R__cl || R__insp.IsA()) { }
R__insp.Inspect(R__cl, R__parent, "fB", &fB);
fB.ShowMembers(R__insp, strcat(R__parent,"fB."));
R__parent[R__ncp] = 0;
TObject::ShowMembers(R__insp, R__parent);
}
and the compiler reports:-
MyDict.cc: In member function `virtual void
A::ShowMembers(TMemberInspector&,
char*)':
MyDict.cc:182: passing `const B' as `this' argument of `virtual void
B::ShowMembers(TMemberInspector&, char*)' discards qualifiers
in this simple case, although in a more complex class it can fail
completely with the error:-
MyDict.cc: In
member function `virtual void A::ShowMembers(TMemberInspector&,
char*)':
MyDict.cc:2162: no matching function for call to
`B::ShowMembers(TMemberInspector&,
char*) const'
B.h:44: candidates
are: virtual void ModelSelector::ShowMembers(TMemberInspector&,
char*) <near
match>
In ROOT 3.10/01 it was fine:-
//______________________________________________________________________
________
void A::ShowMembers(TMemberInspector &R__insp, char *R__parent)
{
// Inspect the data members of an object of class A.
--
if (R__ncp || R__cl || R__insp.IsA()) { }
R__insp.Inspect(R__cl, R__parent, "fB", &fB);
const_cast< B &>( fB ).ShowMembers(R__insp,
strcat(R__parent,"fB.")); R__parent[R__ncp] = 0;
R__cl->SetStreamer("fB",R__A_fB);
TObject::ShowMembers(R__insp, R__parent);
}
The const_cast allowed access to the const member.
The following demonstrate the problem:-
rootcint -f MyDict.cc -c a.h b.h LinkDef.h
g++ -c -I/$ROOTSYS/include MyDict.cc
where a.h:-
#ifndef A_H
#define A_H
#include "TObject.h"
#include "b.h"
class A : public TObject {
public:
A():fB() {}
const B& GetB() const { return fB; }
private:
const B fB;
ClassDef(A,1)
};
#endif //A_H
and b.h:-
#ifndef B_H
#define B_H
#include "TObject.h"
class B : public TObject {
public:
B() : fNum(0) {}
int GetNum() const { return fNum; }
void SetNum(int num) { fNum = num; }
private:
int fNum;
ClassDef(B,1)
};
#endif //B_H
Cheers,
Nick West
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:06 MET