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?
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:
friendclass 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 ).
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).
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.