1

I have a manager that keeps shared_ptr to different type of objects and for all of them provides same specific, but also a common functionality.

I would like to remove the repeating parts with a mixin say like this:

template <typename T>
class ManagerMixin
{
public:
    typedef T MixinObject;
    typedef std::shared_ptr<MixinObject> MixinObjectSPtr;

    MixinObjectSPtr unique(const MixinObjectSPtr& object)
    {
        return *mMixinObjects.insert(object).first;
    }

private:
    std::unordered_set<MixinObjectSPtr> mMixinObjects;
};

Now when I inherit this for more than one class say

class Manager : public ManagerMixin<Object1>, public ManagerMixin<Object2>

the unique method for these both types should be visible, but instead I get

error: member 'unique' found in multiple base classes of different types

Any ideas how I can solve this. From the actual compiler issue to completely different approach.

gsf
  • 6,612
  • 7
  • 35
  • 64
  • 1
    Managers are often quite useless ;) - hiding data modelling –  Dec 31 '15 at 20:08
  • No idea what you mean with that. Managers do not suppose to do data modeling ... no way to hide it. – gsf Dec 31 '15 at 20:12
  • 1
    An MWE (minimum working (or maybe nonworking) example) would be nice here. You are using `MixinObject::Hasher` but your code gives no clue as to what that means. – David Hammen Dec 31 '15 at 20:17
  • mmm - how to solve a data model - no clue - get a manager –  Dec 31 '15 at 20:18
  • 3
    Roughly [this](http://stackoverflow.com/questions/34417645/why-is-a-program-rejected-as-ambiguous-that-could-be-resolved-by-overload-resolu) (and a bunch of older duplicates), modulo the `virtual` part. Lift them to `Manager`'s scope with `using`, or write a template to do it for you if you have so many base classes that it gets unwieldy. – T.C. Dec 31 '15 at 20:21
  • 3
    You need to bring the different unique functions from the base classes to the derived class' overload set. One way of doing it is putting a using declaration at the top of your derived class. (`using ManagerMixin::unique; using ManagerMixin::unique;`) – Blazo Dec 31 '15 at 20:26
  • 1
    @T.C. and @ Blazo thanks, this is what I needed. – gsf Dec 31 '15 at 20:30
  • @DieterLücking this comment is as useless as the first one. The question does not say anything about a data model - and the one without clue is you. – gsf Dec 31 '15 at 20:48
  • @gsf That is exactly your problem, not modelling properly. –  Dec 31 '15 at 20:55
  • @DieterLücking So your data models never require any kind of management - you never use say dedup, cache, factory or anything else that does not belong to the data model? – gsf Dec 31 '15 at 21:01
  • That might be a second step (however a factory is not) –  Dec 31 '15 at 21:13
  • Thank you for the input @DieterLücking, but I am having hard time to make any sense from what you saying. No, to what? What steps - how do you know what step I am? For what factory is not? – gsf Dec 31 '15 at 21:19

0 Answers0