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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:57:22+00:00 2026-06-12T09:57:22+00:00

I have the following union: union employee { char key; struct manager { short

  • 0

I have the following union:

union employee
{
    char key;

    struct manager
    {
        short int age;
        float shares;
        short int level;
    };

    struct worker
    {
        short int age;
        short int skill;
        short int department;
    };

} company[10];

How can I access a member of a structure which is inside the union employee?
I tried to access the age member of the manager structure this way:

company[i].manager.age

But I get error C2039: 'manager' : is not a member of 'employee'.

  • 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-12T09:57:24+00:00Added an answer on June 12, 2026 at 9:57 am

    Add something after the tag declaration. Perhaps:

    struct manager
    {
        short int age;
        float shares;
        short int level;
    } manager;
    

    Side note: you’re not using the union right. The key, i.e. the field that tells you whether you are dealing with a manager or with a mere worker should be in an enclosing object, outside the union. Perhaps:

    struct employee {
        char key;
    
        union {
            struct manager ...;
            struct worker ...;
        } u;
    };
    

    As dasblinkenlight notes, you could declare your manager / worker tags outside the union.

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

Sidebar

Related Questions

More specifically, I have (simplified) the following: union foo { volatile int bits; char
I have following struct defination: typedef union U08_16_t { unsigned long s32;//message32 unsigned char
Hi I have the following union which is part of a larger struct and
Say we have the following code: typedef union { float e[4]; __v4sf v; float
Supposing I have the following type from an external library: union foreign_t { struct
I have the following data types declaration. typedef struct{ int aa; }A; typedef struct{
I have following SQL statementL: select DATE(bla), count(*) from tableA group by DATE(bla) UNION
I have the following recursive function: ALTER FUNCTION [dbo].[ListAncestors] ( @Id int ) RETURNS
I have the following code: /* sample.c */ #include<stdio.h> #include<malloc.h> #include<stdlib.h> #includehermes.h #include<string.h> int
I have the following union query that queries for the most recent date of

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.