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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:19:11+00:00 2026-05-26T18:19:11+00:00

I have a program I am working on that requires us to overload the

  • 0

I have a program I am working on that requires us to overload the >> for the Employee class so that when it’s used it reads in the right type of employee so I have something like this in my main program:

 Employee *emp;
 empIn >> emp;

I figured the base class is where I would want to do it, because it is the only one that applies to all of the derived classes. The type is determined by an integer at the start of the line so I figured that something like this might work (as I don’t know the type until I read it):

istream &operator >> (istream &stream, Employee &emp)
{
   int type;
   stream >> type;
   switch(type){
      case 1:
         *emp = new Hourly;
         break;
           ...
   }
   return stream;
}

But, it doesn’t work. I’m I going about this the right way? And if not, please point me in the right direction.

  • 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-26T18:19:11+00:00Added an answer on May 26, 2026 at 6:19 pm

    The second argument to your istream function should be Employee* &emp if you want to be able to assign to the pointer as in your example usage. The type would then be a reference to a pointer, which lets you assign it as you want to do instead the method.

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

Sidebar

Related Questions

I have a script/program I am working on that requires a configuration file (I
I have a program that I'm working on that register global hotkeys I would
I have a working program in C++ that generates data for a Mandelbrot Set.
I have a simple Delphi program that I'm working on, in which I am
I'm working on a C# program, and right now I have one Form and
Greetings all, I’m working on a C# program that requires being able to get
I'm working on a program for class that involves solving the Chinese Postman problem
I have a program that requires cascaded SSH, i.e. it ssh A server and
I am working on a project that requires me to generate a java .class
I have a program that accepts two file names as arguments: it reads the

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.