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 7979665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:50:07+00:00 2026-06-04T09:50:07+00:00

A common scenario in my code is that I got a functor that is

  • 0

A common scenario in my code is that I got a functor that is used by many classes in a hierachy.

To make it accessible by all classes and stay DRY, I usually define it as a protected inner struct of my base class like that:

class Base
{
protected:
    struct CommonFunctor
    {
        bool operator()()
        {
            return true;
        }
    };
};

class DerivedA : public Base
{
    void FooA()
    {
        bool test = CommonFunctor()();
    }
};

class DerivedB : public Base
{
    void FooB()
    {
        bool test = CommonFunctor()();
    }
};

I don’t like that solution because it clutters my base class with many small functors, that are internal only and even if they are not accessible to the public, they decrease readability of my base class.

Do you know any other solutions for this scenario?

  • 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-06-04T09:50:09+00:00Added an answer on June 4, 2026 at 9:50 am

    Just implement your functors in new files (BaseClassFunctors.cpp + BaseClassFunctors.h). Put them inside your namespace with an optional subnamespaces (e.g. namespace main.internal).

    Now you include the header file in any derived classes you want, without cluttering the base class header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Present Scenario : I have a set of classes that all take a common
Common scenario: I have a library that uses other libraries. For example, a math
Perhaps I'm missing something simple, as I believe that this is a common scenario...
I have a scenario that i suspect is very common, i've found various ideas
I've got a number of scripts that use common definitions. How do I split
We have this common scenario where we have a method that performs some action
I have a Hierarchical project that uses source code from a common system-directory, for
This should be a common scenario, but could not find any relevant post yet..
This is a very common scenario: displaying images in a ListView which have to
So I have a common scenario where everything depends on AJAX responses, followed by

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.