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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:00:31+00:00 2026-05-14T21:00:31+00:00

I have 2 structures that have 90% of their fields the same. I want

  • 0

I have 2 structures that have 90% of their fields the same. I want to group those fields in a structure but I do not want to use the dot operator to access them. The reason is I already coded with the first structure and have just created the second one.

before:

typedef struct{
  int a;
  int b;
  int c;
  object1 name;
} str1;  

typedef struct{
  int a;
  int b;
  int c;
  object2 name;
} str2;

now I would create a third struct:

typedef struct{
  int a;
  int b;
  int c;
} str3;

and would change the str1 and atr2 to this:

typedef struct{
  str3 str;
  object1 name;
} str1;

typedef struct {
  str3 str;
  object2 name;
} str2;

Finally I would like to be able to access a,b and c by doing:

str1 myStruct;
myStruct.a;
myStruct.b;
myStruct.c;

and not:

myStruct.str.a;
myStruct.str.b;
myStruct.str.c;

Is there a way to do such a thing. The reason for doing this is I want keep the integrety of the data if chnges to the struct were to occur and to not repeat myself and not have to change my existing code and not have fields nested too deeply.

RESOLVED: thx for all your answers. The final way of doing it so that I could use auto-completion also was the following:


struct str11
{
int a;
int b;
int c;
};
typedef struct str22 : public str11
{
QString name;
}hi;

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

    Yes. Rather using a C-style of inheritance, using C++ style:

    struct str3{
      int a;
      int b;
      int c;
    };
    
    struct str2 : public str3{
      object2 name;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my code base I find that two modules have structures with the same
Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
I have some data structures that stay unchanged if you try to add something
I have these two data structures that I continually find myself choosing between when
I have 2 SharePoint lists that have identical structures. Is it possible for me
In the data structures class that I am currently taking, we have been tasked
I have a set of core, complicated JavaScript data structures/classes that I'd like to
I have several php scripts that have the following structures: $count = $_GET['count']; $sort
I have some HTML that I need to toggle between two structures - one
I have a C++ application that includes a number of structures with manually controlled

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.