Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7650807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:20:48+00:00 2026-05-31T11:20:48+00:00

Consider a class that is supposed to offer some (polymorphic) methods such as arithmetic

  • 0

Consider a class that is supposed to offer some (polymorphic) methods such as arithmetic or bitwise operators for all its subclasses. These operations should NOT be modifiable by the derived classes to ensure correct execution. However, at the same time I would like to have the evaluation of subclasses (with the function isError() in my example) be individually defined:

class Mom
{
public:
    virtual bool operator && (const Mom&) const final
    {
        return this->isError() && p_rOther.isError();
    }
private:
    virtual bool isError() = 0;
};

This does not seem to be allowed given the current standard, as the “pure virtuality” implies the necessity for subclasses to implement all virtual functions of the baseclass, whereas the “final” keyword contradicts this paradigm.

Any suggestions or ideas how to handle this contradiction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:20:49+00:00Added an answer on May 31, 2026 at 11:20 am

    I assume that you have been misinformed on how pure virtual member-functions are dealt with and what they are for.

    Only member-functions declared to be pure virtual must be defined in the classes inheriting from your base.

    I’m guessing you are confusing it with the fact that the whole Base will become abstract.


    The snippet further down in this post works just fine, and results in the behavior that you have described. Though having a virtual function made final kind of defeats it’s purpose.

    I’d recommend you to remove the virtual specifier.

    This is unless your Base is inheriting from a base where the virtual function is present and you’d like to make this clear to future developers reading your code.


    #include <iostream>
    

    c++11

    struct Base {
      virtual bool operator&& (Base const& rhs) const final {
        std::cerr << "Base ::operator&& ()\n";
    
        return this->error () && rhs.error (); 
      }
    
      virtual bool error () const = 0;
    };
    
    struct Child : Base {
      virtual bool error () const {
        std::cerr << "Child::error ()\n";
    
        return true;
      }
    };
    

    int
    main (int argc, char *argv[])
    {
    
      Child ch1,   ch2;
      ;     ch1 && ch2;
    }
    

    output

    Base ::operator&& ()
    Child::error ()
    Child::error ()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider a class that is supposed to make parameter suggestion, given some clues, and
Task at hand:Consider a class ratingScore that represents a numeric rating for some thing
Consider the class below that represents a Broker: public class Broker { public string
It may not be so obvious how respond_to? works in ruby. Consider that: class
Consider a hypothetical method of an object that does stuff for you: public class
I have a method here that is supposed to produce a System.Drawing.Image instance. Consider
Consider a class OriginalClass that might or might not be available on runtime. OriginalClass
Consider that I have a MainWindow that has the following button declared in its
I am creating a class that implements the composite pattern; the class is supposed
Consider following class class test { public: test(int x){ cout<< test \n; } };

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.