I'm trying to build a class that inherits from another class and initializes itself by parsing a text file. So I have:
On my header file (both in same file):
class Mother{
public:
Mother();
Mother(std::string path);
int parse_textfile(std::string path);
protected:
std::string path;};
class Daughter : public Mother {
public:
Daughter();
Daughter(path);
Daughter(std::string TITLE);
protected:
std::string path
std::string TITLE
Now, on my cpp file:
Mother::Mother(){};
Mother::Mother(string path)
:path(path)
{
parse_textfile(path);
};
Mother::parse_textfile(string path)
{
cout << "Processing file: " << path << endl;
ifstream file(path.c_str());
if (! file){
cerr << "unable to open input file: " << grid_path << " --bailing out! \n";
return -1;
}else{
string TITLE;
getline(file, TITLE);
return Daughter(TITLE)
Now, I understand that this code is not correct (obviously, as it won't compile without errors), but I am still so raw with C++ that some expert advice would really come a long way at this point.
The objective is to create a Daughter class that inherits the parsers, because the Daughter class itself should parse the textfile and hold all the variables in it. I will do line by line parsing because there is a lot of information in the text file. I just want this information to be held on the Daughter object so I can operate over this information later on.
Also, I'm using C++ mainly because I don't want to share the source code. If there is a more appropriate language, I would also like to hear it from you. This would be trivial for me in Python, but again, I don't want to share what's happening.
EDIT 1:
Based on what I got from the comments, I can start seeing more clearly what the specific question should be.
I have 3 text files that belong to the same problem, but each of this text files contain different information.
What I want is to get recommendations on how to initialize each of this text files as individual objects that are derived from the same "Mother class". Maybe it makes more sense that the parser actually belongs to each of the Daughters instead of the Mother. Either way, for those whose comments have been geared towards actually answering the question and not asking me "why I want to do this", I appreciate your help and recommendations.