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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:59:41+00:00 2026-06-16T17:59:41+00:00

I want to make an empty base class called Node, and then have other

  • 0

I want to make an empty base class called “Node”, and then have other classes derived from this such as “DecisionNode” and “Leaf.” It makes sense to do this so I can take advantage of polymorphism to pass these different kinds of nodes to methods without knowing at compile time what will be passed to the method, but each of the derived classes do not share any state or methods.

I thought the best way to implement this, without creating an additional pure virtual method in the base class, which would add clutter, would be to make the constructor pure virtual. In the header file for the class, “Node.h” I therefore wrote:

class Node {
 private:
  virtual Node();
};

and in “Node.cpp” I wrote:

#include "Node.h"
virtual Node::Node() = 0;

This implementation prevents Node from ever being instantiated by another class, since the only constructor is private and uses the pure virtual specifier to indicate that the class is abstract. However, this gives the compiler errors:

Node.h:6:21: error: return type specification for constructor invalid
Node.h:6:21: error: constructors cannot be declared virtual [-fpermissive]

My question is: is there a neat way to make an empty abstract base class?

  • 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-16T17:59:42+00:00Added an answer on June 16, 2026 at 5:59 pm

    C++ doesn’t support virtual constructor.

    § 12.1 Constructors

    12.1.4 A constructor shall not be virtual (10.3) or static (9.4).

    Below code won’t compile:

    virtual Node::Node() = 0;
    

    My question is: is there a neat way to make an empty abstract base
    class?

    Yes, make destructor a pure virtual function, also provides destructor function definition

    class Node 
    {
    public:
        virtual ~Node()=0
        {
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to declare an empty list inside a scheme function. To make this
I have style sheet with a class name changebackgroundcolor i want make change in
I need to make a class Serializable. In this class I have a MyGuid
I want to make a empty column. I tried this select LOSA_APP.app_ref_no AS App.Ref.No.,
i want to make a folder with the project id and then i have
I trying to make an empty CCSprite then I want to hand drawing on
I have a create.js.erb, I want make this: if the user click to create
Let's say I have an empty class with a virtual function: class Base {
i want to make empty textbox checking for android. i tried try catch but
What is needed to make String.IsNullOrEmpty() count whitespace strings as empty? Eg. I want

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.