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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:49:28+00:00 2026-05-22T20:49:28+00:00

Imagine this simple base class: struct simple_http_service { virtual reply http_get(…); virtual reply http_post(…);

  • 0

Imagine this simple base class:

struct simple_http_service
{
  virtual reply http_get(…);
  virtual reply http_post(…);
  virtual reply http_delete(…);
  // etc.
};

I’d like to prevent the user from deriving from this class without overriding at least one of these and prevent them from instantiang simple_http_service

Is there some nice way to do this?

  • 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-22T20:49:29+00:00Added an answer on May 22, 2026 at 8:49 pm

    That sounds like a really odd constraint. By all means protect the user from incorrect usage, but don’t try to prohibit things that you just “can’t see the point of”. If there’s no point in deriving from your class without overriding any of the three functions, then let the user override as many or as few function as he likes, and trust that he won’t do the pointless thing of deriving without overriding any of the functions. There’s no harm in the user doing that, it’s just not very useful.

    But if you do need to enforce this (again, I’d suggest you rethink), then don’t use virtual functions. Instead, pass function pointers or function objects (or std::function/boost::function) callbacks. Make the base class look something like this:

    struct simple_http_service
    {
      typedef std::function<reply (...)> func_type;
      reply http_get(...) { return get_func(...); }
      reply http_post(...) { return post_func(...); }
      reply http_delete(...) { return delete_func(...); }
      // etc.
    
    private:
      func_type get_func;
      func_type post_func;
      func_type delete_func;
    };
    

    Now just add the necessary constructors (or free/static functions so you can name them to avoid ambiguity) so that the class can only be instantiated when at least one of the function objects are supplied.

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

Sidebar

Related Questions

I've never learnt JavaScript, but I imagine this is quite a simple problem. Just
Imagine this sample java class: class A { void addListener(Listener obj); void removeListener(Listener obj);
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I've got a base class for all my custom entity collections, a simple version
I have this class that has a static member. it is also a base
Like this: public class remoteStatusCounts : RemoteStatus { public int statusCount; public remoteStatusCounts(RemoteStatus r)
Simple Question. Imagine this in ANSI-C: int i; for(i=0 ; i<5 ; i++){ //Something...
I imagine this is pretty simple, but can't figure it out. I'm trying to
Imagine the following two entities. Element is simple class containing some data: @Entity public
I'm only just learning javascript so I imagine this is relatively simple but it's

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.