Menu

Questionable duplInheritedMember false positive with a const and non-const version

2024-05-15
2024-05-15
  • Steve Albright

    Steve Albright - 2024-05-15

    warning: duplInheritedMember - The class 'SomeClass' defines member function with name 'GetObject' also defined in its parent class 'SomeInterfaceClass'

    class SomeInterfaceClass
    {
    public:
       virtual QObject& GetObject() = 0;
    };
    
    class SomeClass: public SomeInterfaceClass
    {
    public:
       QObject& GetObject() override { return TheObject; }
    
    private:
       QObject& GetObject() const { return TheObject; }
    
       mutable QObject TheObject;
    };
    
     

    Last edit: Steve Albright 2024-05-15
  • CHR

    CHR - 2024-05-15

    The example doesn't compile since the private GetObject() cannot return a non-const reference. When const is added, there is no FP.

     
    • Steve Albright

      Steve Albright - 2024-05-15

      Sorry about that, I missed the fact that we have a mutable object.

       
      👍
      1

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.