1

What is the best way to avoid Warning C4250 (inheritance via dominance)?

I am using MS VS 2013 Community edition.

I have the following code:

interface IHEEntity
{
    public:
        virtual size_t GetId() const = 0;
        virtual void SetId(const size_t Value) = 0;
    public:
        virtual ~IHEEntity() {};
};

class CHEEntity : public virtual IHEEntity
{
    protected:
        size_t m_Id;
    public:
        size_t GetId() const final { return m_Id; }
        void SetId(const size_t Value) final { m_Id = Value; }
    public:
        CHEEntity() {};
        virtual ~CHEEntity() {};
};

interface IHEArc : public virtual IHEEntity
{
    public:
}

class CHEArc :
    public virtual CHEEntity,
    public virtual IHEArc
{
    public:
        using CHEEntity::GetId;
        using CHEEntity::SetId;
}

When I try to compile it, I get the aforementioned warning. Is there any way to get rid of that warning without using warning suppression via pragma? Or there might be any other way to achieve the intended result?

John Odom
  • 1,189
  • 2
  • 20
  • 35
Vasya Ar
  • 29
  • 4
  • 1
    What does *"Warning C4250"* say? – Baum mit Augen Oct 20 '15 at 21:37
  • 2
    Welcome to StackOverflow! This [StackOverflow answer](http://stackoverflow.com/a/2190971/2843157) has a nice description on what this warning means and why it happens. – John Odom Oct 20 '15 at 21:39
  • @BaummitAugen It reads "warning C4250: 'CHEArc' : inherits 'CHEEntity::CHEEntity::GetId' via dominance" – Vasya Ar Oct 20 '15 at 21:50
  • @JohnOdom Thank you for the link. I have already read it. I've tried using "using CHEEntity::GetId;" but still get the warning. I've also read some similar questions and answers stating that virtual inheritance is a bad practice in such situations. What should I change in the code then? I am just not that proficient and I tend to think I need to change the class design. So I need a good advice. – Vasya Ar Oct 20 '15 at 21:58
  • Why don't you want to suppress it? You've read the warning and decided it doesn't matter here; why not tell the compiler that? – Alan Stokes Oct 20 '15 at 22:38
  • @AlanStokes Well, I am not sure it will not cause me problems afterwards. I think I will have to if I cannot find a proper solution – Vasya Ar Oct 20 '15 at 22:48
  • What version of C++ are you using? I don't recall the keyword `interface` in *standard* C++. – Thomas Matthews Oct 21 '15 at 01:34
  • @ThomasMatthews I am using MS VS 2013 Community edition. You can find explanation here [link](http://stackoverflow.com/questions/25234203/what-is-the-interface-keyword-in-msvc) – Vasya Ar Oct 21 '15 at 06:31

0 Answers0