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

  • Home
  • SEARCH
  • 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 8238213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:44:04+00:00 2026-06-07T19:44:04+00:00

I have a C-header file with 100s of data structs. I want to make

  • 0

I have a C-header file with 100s of data structs. I want to make a superclass that each data struct inherits from. How to do that? Should I parse the header file? Reflection?

Because each C data struct is a public class, I could just make a superclass and… then what? I should not go in manually and explicitly make every struct inherit from the superclass?

  • 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-07T19:44:06+00:00Added an answer on June 7, 2026 at 7:44 pm

    If you have a bunch of structs:

    The obvious answer is to make clever use of search and replace to make them inherit from the new base class. It wouldn’t be able to access the members of the structs, but you could store pointers to them all in containers

    struct base {
        int dostuff() const {std::cout << "thing";}
    };
    struct thing1 : public base {
        int size;
    };
    //otherstructs inheriting from base
    int main() {
        std::vector<std::unique_ptr<base>> objects;
        objects.push_back(std::unique_ptr<base>(new thing1()));
        objects[1].dostuff();
    }
    

    If making the base class thing is too hard, you might try adding functions via a wrapper class instead. You won’t be able to store pointers to these in a container, but they can access members, as long as the structs have similar members.

    struct thing1 {
        int size;
    };
    //other unchanged structs
    template<class mystruct>
    struct wrapper : mystruct {
        int getsize() {return mystruct.size;}
    };
    
    int main() {
         wrapper<thing1> mything1;
         std::cout << mything1.size << mything1.getsize();
    }
    

    Or, if you’re just adding methods, make them separate functions:

    struct thing1 {
        int size;
    };
    //other unchanged structs
    template<class T>
    int getsize(const T& obj) {return obj.size;}
    
    int main() {
         thing1 mything1;
         std::cout << mything1.size << getsize(mything1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a header file in which I have defined a struct. I want
I have a header file defining some structs I want to use in my
I have a header file which contains several struct definitions. I want to extract
I have a header file, lets say Common.h, that is included in all of
I have C header file containing the following type definition: // example.h typedef struct
I have a header file. In this header I want to use a map
I have a header file that is going to contain a large amount (30+)
I have a header file, wich contain a unsigned char array that is in
I have a header file in which there is a large struct. I need
Lets say that I have a header file a.hxx which includes b.hxx and c.hxx.

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.