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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:32:22+00:00 2026-06-03T19:32:22+00:00

I am trying to simulate inheritance in C, so I created a C file

  • 0

I am trying to simulate inheritance in C, so I created a C file in Visual Studio and wrote some code. I made sure that there were no IntelliSense errors and compiled the code, and it then told me there were over 40 errors. Why didn’t it mention them before? What’s the basic way to get the code to work? (I know some Java, but not much C.)

#include <stdio.h>
#include <string.h>

//Create a manager which should inherit from employee

int main(void)
{
    // construct a Manager object
    double d = 8000;
    char carl[] = "Carl";
    Manager boss= newManager(carl, d, 1987, 12, 15);
    setBonus(&boss, 5000);

    typedef union{ //typedef!?
       Employee e;
       Manager m;
      } Person;

    Person staff[3];    
    // fill the staff array with Manager and Employee objects
      staff[0].m = boss;    
      Employee harry; harry = newEmployee("Harry", 50000, 1989, 10, 1);
      staff[1].e=harry;    
      Employee tommy; tommy = newEmployee("Tommy", 40000, 1990, 3, 15); 
      staff[2].e = tommy;

      // print out information about all Employee objects
      int i;
      for (i=1;i<3;i++){
          //check if employee or manager
          Employee em; em = staff[i].e;
          printf ("%s\n", em.name); 
          printf("%s\n", 345);
      }     
}   

typedef struct {    
    char name[20]; 
    double salary;
    } Employee;

Employee newEmployee(char n[], double s, int year, int month, int day)
{
    Employee emp;
    strncpy(emp.name, n, 20);
    emp.salary=s;    
    return emp;  
}

//use pointer to change actual value
void raiseSalary(Employee (*emplo), double byPercent)  
{   
    double raise = (*emplo).salary * byPercent / 100;
    (*emplo).salary += raise;
}

//Manager struct inheriting from employee struct
typedef struct {
    Employee employee;   
    int bonus;
} Manager;      

Manager newManager(char n[], double s, int year, int month, int day)
{
    Manager man;    
    strncpy(man.employee.name, n, 20);
    man.employee.salary = s;
}

double getManagerSalary(Manager man)
{
    double basesalary = man.employee.salary;
    return basesalary + man.bonus;
}

void setBonus(Manager* man, int b)
{
    (*man).bonus = b;
}
  • 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-03T19:32:28+00:00Added an answer on June 3, 2026 at 7:32 pm

    The Intellisense for C++ is notoriously unreliable and just because something is or isn’t reported as an error by Intellisense doesn’t really mean much.

    Also, whenever you have errors, you have to give us the errors or we most likely won’t be able to help you.

    One thing is obvious though: move the definitions of structs and the prototypes for the functions above main so you don’t have a bunch of undefined functions and structures.

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

Sidebar

Related Questions

I'm trying to simulate some code that I have working with SQL but using
Trying to simulate a HTTP POST that needs to combine some INPUT/TEXT fields along
I am trying to simulate a simple MIPS processor using behavior code in Verilog.
I am trying to write a shell script to simulate the following problem: File
I'm trying to test some scripting that will run on non-English Windows installations. I'm
Using VS2008, we would like to simulate a file that has a size of
I'm trying to simulate the Matrix code rain with the canvas element and javascript.
I'm trying to simulate a simple download application by copying a file like myBook.txt
I'm trying to simulate n games of craps. The code seems to make sense
So I am trying to simulate that the phone is receiving a call. I

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.