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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:22:02+00:00 2026-06-04T18:22:02+00:00

I try to access in a C program data received from a C++ library

  • 0

I try to access in a C program data received from a C++ library which has been originally designed with structure inheritance:

example:

// C++ data structures
typedef struct _Base
{
public:
    int id;
    wchar_t* name;
} Base;


typedef struct _Struct1 : Base
{
public:
    int valueCount;
} Struct1;


typedef struct _Struct2 : Base
{
public:
    int parentID;
    int amount;
} Struct2;

I tried using the following data structures in C for mapping.

typedef struct _Base
{
    int id;
    wchar_t* name;
} Base;


typedef struct _Struct1
{
    // Base struct data
    int id;
    wchar_t* name;

    int valueCount;
} Struct1;


typedef struct _Struct2
{
    // Base struct data
    int id;
    wchar_t* name;

    int parentID;
    int amount;
} Struct2;

But printing the data, it looks like I get wrong values.

Am I missing something, any reference on how C++ represents inherited structure internally?

Thanks in advance!

  • 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-04T18:22:03+00:00Added an answer on June 4, 2026 at 6:22 pm

    The C++11 rules on PODs (What are Aggregates and PODs and how/why are they special?) specify that don’t allow mixing concrete base classes with data members, but in practice for most compilers having a single POD base class is equivalent to encapsulating that class as the first member.

    Try specifying your C structs encapsulating the base struct:

    typedef struct _Struct1
    {
        Base base;
        int valueCount;
    } Struct1;
    

    Note that this won’t work if the C++ classes are non-POD (e.g. have virtual methods).

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

Sidebar

Related Questions

When you try to access a key which isn't in a Dictionary (for example),
I try to access the MainContentBlock control from the aspx, but unable to do
When I try to access the Host object from a non-static method declared in
Well, I stepped in it now. I'm converting a program from Access vba to
i have made a program in which i make a file in the data/data/mypackagename/
i am getting a serious issue Program received signal: EXC_BAD_ACCESS. Data Formatters temporarily unavailable,
I've been trying to get my rails program to access an existing sql express
I need to send some data to a C program from my app in
Suppose I want to run some program which requests too many permissions. For example,
I'm making a program that can access data stored inside a class. So for

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.