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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:25:44+00:00 2026-05-10T16:25:44+00:00

Anyone knows if is possible to have partial class definition on C++ ? Something

  • 0

Anyone knows if is possible to have partial class definition on C++ ?

Something like:

file1.h:

   class Test {     public:         int test1(); }; 

file2.h:

 class Test {     public:         int test2(); }; 

For me it seems quite useful for definining multi-platform classes that have common functions between them that are platform-independent because inheritance is a cost to pay that is non-useful for multi-platform classes.

I mean you will never have two multi-platform specialization instances at runtime, only at compile time. Inheritance could be useful to fulfill your public interface needs but after that it won’t add anything useful at runtime, just costs.

Also you will have to use an ugly #ifdef to use the class because you can’t make an instance from an abstract class:

 class genericTest {     public:         int genericMethod(); }; 

Then let’s say for win32:

 class win32Test: public genericTest {     public:         int win32Method(); }; 

And maybe:

 class macTest: public genericTest {     public:         int macMethod(); }; 

Let’s think that both win32Method() and macMethod() calls genericMethod(), and you will have to use the class like this:

  #ifdef _WIN32  genericTest *test = new win32Test();  #elif MAC  genericTest *test = new macTest();  #endif   test->genericMethod(); 

Now thinking a while the inheritance was only useful for giving them both a genericMethod() that is dependent on the platform-specific one, but you have the cost of calling two constructors because of that. Also you have ugly #ifdef scattered around the code.

That’s why I was looking for partial classes. I could at compile-time define the specific platform dependent partial end, of course that on this silly example I still need an ugly #ifdef inside genericMethod() but there is another ways to avoid that.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T16:25:45+00:00Added an answer on May 10, 2026 at 4:25 pm

    This is not possible in C++, it will give you an error about redefining already-defined classes. If you’d like to share behavior, consider inheritance.

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

Sidebar

Ask A Question

Stats

  • Questions 145k
  • Answers 145k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is unfortunately no such class, at least in the… May 12, 2026 at 8:54 am
  • Editorial Team
    Editorial Team added an answer Here's an attempt. function foo() { jQuery("#mydiv").animate({opacity: 1.0}, {duration: 3000})… May 12, 2026 at 8:54 am
  • Editorial Team
    Editorial Team added an answer When I need to do this, I put each group… May 12, 2026 at 8:54 am

Related Questions

I have some extra functionality i need to add which includes adding a new
does anyone know if its possible to remove a css link at run time...
Today I first saw the potential of a partial accidental deletion of a colleague's
I was wondering if it is possible, as my 5 minutes of experimentation proved

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.