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

  • Home
  • SEARCH
  • 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 3428602
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:58:43+00:00 2026-05-18T06:58:43+00:00

I have the following data-structure as a class named Task: private: string name; int

  • 0

I have the following data-structure as a class named “Task”:

private:
string name;
int computation_time;
int period;

Furthermore i have a ASCII-File with this content:

A 3 10
B 2 12
C 1 11

name = A, computation_time = 3, period = 10 and so on….

Now i want to read in the file, create Task-object and push it back into a vector:

void read_in_task_list_and_create_tasks(const string &filename, vector<Task> &current_tasks)
{
    ifstream in_file;
    in_file.open(filename.c_str());

    string tmp_name;
    int tmp_computation_time;
    int tmp_period;

    while(!in_file.eof())
    {
        in_file >> tmp_name;
        in_file >> tmp_computation_time;
        in_file >> tmp_period;

//        Task tmp_task(tmp_name, tmp_computation_time, tmp_period);
//        current_tasks.push_back(tmp_task);
        current_tasks.push_back(Task(tmp_name, tmp_computation_time, tmp_period));
    }
}

Now, when i take a look into current_tasks vector, it has elements, but their values dont match my in_file values.
Watch the outcommented lines. tmp_task object is exactly correct, but if it’s getting pushed back, it loses it’s values like descriped above.

Could this be a Copy-Constructor Issue in Task-class, because std::vector is managing the memory-allocation?

I’m using netbeans with g++ compiler on Linux x86.

THX

  • 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-18T06:58:44+00:00Added an answer on May 18, 2026 at 6:58 am

    Make sure there are no copy constructors or assignment operators defined.

    The automatic ones should do exactly what you want.

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

Sidebar

Related Questions

Suppose I have the following object: class Foo(object): def __init__(self, name=None): self.name = name
I have the following structure: class Base { } class Child : Base {
I have the following structure: class FeatureType(models.Model): type = models.CharField(max_length=20) def __unicode__(self): return self.type
Lets look at the following structure first (I have tried to simplify it to
Suppose I have the following html: var testString = ' <span id='id'> <div> <table>
Consider this scenario: I've an XML file called person.xml with the following data in
I am attempting to implement a tagging system into my asp.net MVC project. When
I would like to know to to write most efficient LINQ ( EDIT :
This post contains a lot of code, but I would really appreciate it if
This same question was asked here and an answer was given which is workable,

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.