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

Related Questions

Anyone knows if String Aggregation in sqlite is possible? If i have an animal
Possible Duplicate: Minify / Obfuscate PHP Code I have a php file. Anyone knows
I'm wondering if anyone knows if it's possible in XAML to have a ListBox
Does anyone know if it's possible to have a bundle use the annotation reader
Anyone knows if this is possible? I tried it in vs 2005 and 2008
Does anyone knows, it is possible to add a automatic photo to FB timeline
I was wondering if anyone knows how to or if it is possible to
Possible Duplicate: Hibernate and no PK Anyone knows how to do hibernate mapping for
I was wondering if anyone knows how (or even if it is possible) to
Possible Duplicate: What does a type followed by _t (underscore-t) represent? Does anyone knows

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.