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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:52:59+00:00 2026-06-09T16:52:59+00:00

Talking about structs, is it possible to just copy a struct ‘s fields to

  • 0

Talking about structs, is it possible to just copy a struct‘s fields to another struct without explicitly calling the type field name?

Let me show you an example:

struct StructA
{
   char Name[20];
   int Age;
};

struct StructB
{
   StructA FieldStructA;

   int SomeOtherDeclarations;
   // ...
};

So, I could access the StructA fields on StructB doing this:

StructB strB;
strB.FieldStructA.Name[0] = 0;

What I want to do is access the StructA fields through StructB without accessing the data field on StructB. Something like inheritance between classes. Like this:

StructB strB;
strB.Name[0] = 0;

I want to inherit StructA fields on StructB. I know that I could do that with classes, but I have to use struct for some reasons (interop, specific use of stack and so on).

Thanks for your time!

  • 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-09T16:53:00+00:00Added an answer on June 9, 2026 at 4:53 pm

    If you are using gcc, try making it an anonymous member:

    http://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html

    struct StructA
    {
      char Name[20];
      int Age;
    };
    
    struct StructB
    {
       struct StructA;
    
       int SomeOtherDeclarations;
       // ...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not talking about Linq to SQL. Just Linq to DataSet. Let's say I
Just beginning to learn about structs, I thought I understood how they work, using
Talking about javax.crypto.Cipher I was trying to encrypt data using Cipher.getInstance(RSA/None/NoPadding, BC) but I
Talking about SimpleModal the jQuery plugin. Most of the time I think it is
Talking about System.Collections.Generic.List<T> here. With example below can Method1 and Method2 execute and the
When talking about object marshalling in most of the Java-XML data binding APIs, it
Im talking about performing a deep recursion for around 5+ mins, something that you
When talking about HTTPUrlConnection on his blog Tim Bray gives us the following snippet
I'm talking about both server-side and client-side. I know a little bit about Go,
I'm talking about ivy 2, not some newer version.

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.