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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:01:10+00:00 2026-05-29T23:01:10+00:00

Is it possible, in C++ or any other compiled language, to add functionality to

  • 0

Is it possible, in C++ or any other compiled language, to add functionality to a class without modifying the header?

In JavaScript I can add a function to an object after the object is created. Is anything even remote possible in C++?

A use example would be for me to provide a user with some routine.o file, and have them extend it, with something like

void routine::NeverBeforeDeclaredFunction() { ... }

This exact example isn’t allowed, but is anything similar? I’ve thought about letting this class have an array of function pointers, and have a user populate that array with their own function. But this doesn’t provide any advantage, such as access to private variables, or access to 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-29T23:01:11+00:00Added an answer on May 29, 2026 at 11:01 pm

    Is it possible, in C++

    No, you cannot do that at runtime nor at compile time in C++. At least not portably without many headaches. You can create a subclass, but then it’s not “the same class”. If the class is a template class, you could provide your own specializations (but then it’s a different type).

    C++/CX (a Microsoft language extension to C++) allows for partial classes. This might be a solution to your problem, if you don’t care about portability. Note that it is done at compile-time.

    or any other compiled language, to add functionality to a class without modifying the header?

    Objective-C allows this through categories (compile time) and through the Objective-C runtime (runtime).

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

Sidebar

Related Questions

Is it possible in Java (or any other language) to detect if there's an
Any other tweaks for making emacs as vim-like as possible would be appreciated as
Possible Duplicate: Any way to add HttpHandler programatically in .NET? Is there a way
Is there any relevance of a public constructor in an abstract class? I can
I am wondering, are there any languages allows you to add/delete/update any class on
Is there a notion of object-private in any OOP language ?? I mean more
Is there any possible way to PLAY a you tube video on page load
Is there any possible way to apply more than CSS to a control through
Is it possible under any set of circumstances to be able to accomplish this?
Is it possible via any Unix utility to read chunks of a remote file

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.