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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:29:23+00:00 2026-05-24T03:29:23+00:00

I have two lines of code I want explained a bit please. As much

  • 0

I have two lines of code I want explained a bit please. As much as you can tell me. Mainly the benefits of each and what is happening behind the scenes with memory and such.

Here are two structs as an example:

struct Employee 
{
    std::string firstname, lastname;
    char middleInitial;
    Date hiringDate; // another struct, not important for example
    short department;
};

struct Manager
{
    Employee emp; // manager employee record
    list<Employee*>group; // people managed
};

Which is better to use out of these two in the above struct and why?

list<Employee*>group;
list<Employee>group;
  • 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-24T03:29:23+00:00Added an answer on May 24, 2026 at 3:29 am

    First of all, std::list is a doubly-linked list. So both those statements are creating a linked list of employees.

    list<Employee*> group;
    

    This creates a list of pointers to Employee objects. In this case there needs to be some other code to allocate each employee before you can add it to the list. Similarly, each employee must be deleted separately, std::list will not do this for you. If the list of employees is to be shared with some other entity this would make sense. It’d probably be better to place the employee in a smart pointer class to prevent memory leaks. Something like

    typedef std::list<std::shared_ptr<Employee>> EmployeeList;
    EmployeeList group;
    

    This line

    list<Employee>group;
    

    creates a list of Employee objects by value. Here you can construct Employee objects on the stack, add them to the list and not have to worry about memory allocation. This makes sense if the employee list is not shared with anything else.

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

Sidebar

Related Questions

I have a script that generates two lines as output each time. I'm really
I have the following two lines of code that both run fine in both
Suppose I have two buttons btnCheck and btnOK. I want to execute few lines
I have a UILabel with space for two lines of text. Sometimes, when the
Suppose I have two documents that are identical except the lines are shuffled. Is
I have written an app in C which expects two lines at input. First
I have a file named file with three lines: line one line two line
I want to have two items on the same line using float: left for
We want to have two .NET apps running on the same machine communicate with
I have two streams that i want to combine into one stream. The first

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.