[cfe-dev] How to determine base class direct or not?

John McCall rjmccall at apple.com
Thu Nov 10 13:27:06 PST 2011


On Nov 10, 2011, at 5:35 AM, r4start wrote:
> Can anybody help me with following problem. I have such code:
> class B {
> public:
>   virtual void b(){}
>   double b_field;
> };
> 
> struct D : B {
>   virtual void fr(){}
> };
> 
> class C {
> public:
>   virtual void C_f(){}
> };
> 
> class A : public C,
>           public virtual D {
> public:
>   int a_field;
>   virtual void a(){}
> };
> class A1 : public C, public B,
>           public virtual D {
> public:
>   int a_field;
>   virtual void a(){}
> };
> 
> I write function that determines "Has class and his bases a common base?".
> For example for class A this function returns false and for class A1 - 
> true. In A1 as you can see B is base class for A1 and for D.
> I tried to use isDerivedFrom(), but this function searches path from A 
> to B(path is A->D->B) and if path exists return true.
> I need something like isDirectDerivedFrom.
> 
> So my question is, what is the best way to determine these relations?

You're trying to ask whether a type is directly named by one
of the base specifiers?  I don't think we have a utility function
for that, but you can just walk the class's base specifiers directly.

John.



More information about the cfe-dev mailing list