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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:39:30+00:00 2026-06-12T21:39:30+00:00

Possible Duplicate: How do you declare an interface in C++? This is a general

  • 0

Possible Duplicate:
How do you declare an interface in C++?

This is a general question about C++. As you know, there is no clear distinction between interface and abstract class in C++ unlike Java and C#. When would it be more preferrable to use an interface instead of an abstract class in C++? Could you give some examples?

  • 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-12T21:39:32+00:00Added an answer on June 12, 2026 at 9:39 pm

    I assume that with interface you mean a C++ class with only pure virtual methods (i.e. without any code), instead with abstract class you mean a C++ class with virtual methods that can be overridden, and some code, but at least one pure virtual method that makes the class not instantiable.
    e.g.:

    class MyInterface
    {
    public:
      // Empty virtual destructor for proper cleanup
      virtual ~MyInterface() {}
    
      virtual void Method1() = 0;
      virtual void Method2() = 0;
    };
    
    
    class MyAbstractClass
    {
    public:
      virtual ~MyAbstractClass();
    
      virtual void Method1();
      virtual void Method2();
      void Method3();
    
      virtual void Method4() = 0; // make MyAbstractClass not instantiable
    };
    

    In Windows programming, interfaces are fundamental in COM. In fact, a COM component exports only interfaces (i.e. pointers to v-tables, i.e. pointers to set of function pointers). This helps defining an ABI (Application Binary Interface) that makes it possible to e.g. build a COM component in C++ and use it in Visual Basic, or build a COM component in C and use it in C++, or build a COM component with Visual C++ version X and use it with Visual C++ version Y.
    In other words, with interfaces you have high decoupling between client code and server code.

    Moreover, when you want to build DLL’s with a C++ object-oriented interface (instead of pure C DLL’s), as described in this article, it’s better to export interfaces (the “mature approach”) instead of C++ classes (this is basically what COM does, but without the burden of COM infrastructure).

    I’d use an interface if I want to define a set of rules using which a component can be programmed, without specifying a concrete particular behavior. Classes that implement this interface will provide some concrete behavior themselves.

    Instead, I’d use an abstract class when I want to provide some default infrastructure code and behavior, and make it possible to client code to derive from this abstract class, overriding the pure virtual methods with some custom code, and complete this behavior with custom code.
    Think for example of an infrastructure for an OpenGL application.
    You can define an abstract class that initializes OpenGL, sets up the window environment, etc. and then you can derive from this class and implement custom code for e.g. the rendering process and handling user input:

    // Abstract class for an OpenGL app.
    // Creates rendering window, initializes OpenGL; 
    // client code must derive from it 
    // and implement rendering and user input.
    class OpenGLApp
    {
    public:
      OpenGLApp();
      virtual ~OpenGLApp();
      ...
    
      // Run the app    
      void Run();
    
    
      // <---- This behavior must be implemented by the client ---->
    
      // Rendering
      virtual void Render() = 0;
    
      // Handle user input
      // (returns false to quit, true to continue looping)
      virtual bool HandleInput() = 0;
    
      // <--------------------------------------------------------->
    
    
    private:
      //
      // Some infrastructure code
      //
      ... 
      void CreateRenderingWindow();
      void CreateOpenGLContext();
      void SwapBuffers();
    };
    
    
    class MyOpenGLDemo : public OpenGLApp
    {
    public:
      MyOpenGLDemo();
      virtual ~MyOpenGLDemo();
    
      // Rendering
      virtual void Render();  // implements rendering code
    
      // Handle user input
      virtual bool HandleInput(); // implements user input handling
    
    
      //  ... some other stuff
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why would one declare a Java interface method as abstract? The following
Possible Duplicate: Why would one declare a Java interface method as abstract? I found
Possible Duplicate: Default class inheritance access I know I can set the protection level
Possible Duplicate: Does Objective-C guarantee the initialization of interface member data? When I declare
Possible Duplicate: declare property as object? class core { public $dbh = new PDO(mysql:dbname=newdbnaem;host=1.1.1.1:1111,
Possible Duplicate: Class methods which create new instances How would you declare a constructor
Possible Duplicate: VB.Net Initialising an array on the fly This maybe a stupid question,
Possible Duplicate: Is there any reason to declare ivars if you're using properties exclusively
First, I know my question would be possibly duplicate of this one , but
Possible Duplicate: How do you declare an interface in C++? Hi, What's the preferable

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.