Private inheritance multiple times from same class

Hi,
I've been working on a program that uses a reference counting class that I've written which works fine for objects that inherit from it however I now need to have the following setup:
1
2
class SBComponent : private Refcounted { /*stuff*/}
class ProxiedComponent : public SBComponent, private Refcounted {/*stuff*/}


The compiler gives the following warnings
warning: direct base ‘Refcounted’ inaccessible in ‘ProxiedComponent’ due to ambiguity

And then several repeats of the error:
1
2
error: request for member ‘bk’ is ambiguous
Back *b = bk<ProxiedComponent>();


bk is a templated function that's defined in Refcounted and returns a pointer of type <template arg>::Back (ProxiedComponent::Back in this case).

I don't understand why the call to bk is ambiguous as although there's two instances of Refcounted (there needs to be with the way I've designed it so I can't make it virtual) it's inheritance is private in both cases so there should only be one instance of it visible in ProxiedComponent.

Is there something I'm doing wrong or an easy was to fix it?

Thanks
there needs to be with the way I've designed it
This sounds iffy.
At the moment the reason I need to have multiple copies of the Refcounted class is that it contains a pointer to an instance of Back object which contains all the data associated with this instance of the the Reference counted class. A component would be
1
2
3
4
5
6
7
8
9
10
11
12
13
class Component : private Refcounted {
    private:
        friend class Refcounted;
        class Back {
            public:
                bool prop;
        }
    public :
        Component () : Refcounted(new Back()) {}
        bool getProp() {
            return bk<Component>()->prop;
        }
}


In the first example that's giving me problems the two instances of the of the Refcounted object have pointers that point to the Back objects for the two different classes (SBComponent & ProxiedComponent ).
Use protected virtual inheritance, or use CRTP. I don't understand why you would want it the way you currently have it.
I tried doing it through CRTP before but I got a load of template errors as the function bk was ( when I was trying to make Refcounted a templated class).
1
2
3
typename T::Back* bk() const {
	return (typename T::Back*) bob;
}

And refers to T::Back before T::Back is declared. I tried doing forward declaration but couldn't seem to fix it.
I'll give it another go though.

Thanks
It should not be a problem because member functions are not instantiated until they are used.
it's inheritance is private in both cases so there should only be one instance of it visible in ProxiedComponent.
Classic C++ trap. Private/protected/public are not visibility modifiers. They are access modifiers. All private names are still visible outside and participate in overload resolution.
Ah ok, thanks!
Topic archived. No new replies allowed.