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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:42:34+00:00 2026-06-18T00:42:34+00:00

At class instantiation, I would like to read data from a file and process

  • 0

At class instantiation, I would like to read data from a file and process it into a number of class objects. What I did so far (and works well) is

myData::myData(const std::string & file):
  data1_(this->read(file)),
  processedData1_(this->createProcessedData1_(data1_)),
  processedData2_(this->createProcessedData2_(data1_)),
  processedData3_(this->createProcessedData3_(data1_))
{
}

In a different class, the read() method creates more than one raw data object. In this case, I don’t know how to pack things into the initializer list, so I’m doing something along the lines of

myData::myData(const std::string & file):
  data1_(),
  data2_(),
  processedData1_(),
  processedData2_(),
  processedData3_()
{
  this->read(file); // fills data1_, data2_
  processedData1_ = this->createProcessedData1_(data1_, data2_);
  processedData2_ = this->createProcessedData2_(data1_, data2_);
  processedData3_ = this->createProcessedData3_(data1_, data2_);
}

What I don’t like about this approach is that

  • the data is initalized twice: once (void) in the initializer list, once filled with actual content in the constructor; and that
  • I cannot mark any of the (processed) data objects as const.

Is there a way to organize the object creation such that it all happens in the initialization list?

  • 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-18T00:42:36+00:00Added an answer on June 18, 2026 at 12:42 am

    You may think about splitting the data loading / processing in a factory-like static method that in turn constructs a myData instance (passing the processedData*_ values as constructor params).

    This way you can keep the loading and processing separate from the class that may end up just storing the results and possibly provide further processing or accessors to parts of the data.

    Could something like

    class MyData {
    public:
        MyData(DataType processedData1, ...) : processedData1_(processedData1) ... { }
    private:
        const DataType processedData1_;
    }
    
    struct DataContainer {
        DataType data1;
        DataType data2;
    }
    
    DataContainer read(const std::string& file) { ... }
    
    DataType createProcessedData1(DataType data) { ... }
    ...
    
    // hands ownership to caller
    MyData* LoadData(const std::string & file) {
        DataContainer d = read(file);
        return new MyData(createProcessedData1(d.data1), createProcessedData2(d.data2), ..)
    }
    

    work for you?

    I’m assuming you don’t need to keep state when loading and processing data. If this isn’t the case you can make read and createProcessedData* members of a MyDataLoader class.

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

Sidebar

Related Questions

I would like to make a data manager class that retrieves data from plist,
I have a class and I would like to restrict its instantiation to only
I have a class that contains some data, and I would like to add
I would like to share data between the objects. Actually, for example, there is
I have a class assignment to read in data using Scanner. import java.util.Scanner; public
I am developing in python a file class that can read and write a
I am writing a simple vector class and I would like to have some
I have a class template Z that I would like specialize when passed a
I would like to define a template function but disallow instantiation with a particular
I have come across some behaviour from R reference classes I would like to

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.