G
Gary Wessle
Hi
this code of mine, is my first attempt at inheritance. it is buggy and
I am sure there are few errors, it did not compile and I could not
find out why, please help.
thank you
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
using namespace std;
class Task {
protected:
string f_path;
short s_status;
string name;
string menu_item;
void load_status() {
string sf = f_path + name + "_s.txt";
ifstream in( sf.c_str() );
string s;
getline(in, s);
stringstream st(s.c_str());
st >> s_status;
}
public:
Task(string n, string mi) :
name( n ),
menu_item( mi ),
f_path( "../str1/status/" )
{
load_status();
}
void p_menu_item() const {
cout << menu_item << endl;
}
virtual void preform();
};
class Thr_task : public Task {
public:
Thr_task(string n, string mi) :
Task(n, mi) {}
void preform();
void pref_thr();
};
class No_thr_task : public Task {
public:
No_thr_task(string n, string mi):
Task(n, mi){}
void preform();
};
int main(){
No_thr_task nt1("sometask", "Taaask str1");
Thr_task t1("optm_upd", "Update and optimization");
nt1.p_menu_item;
t1.p_menu_item;
}
the errors relate to function overloading for the 2 lines above, and
also in relation to vtable and references.
this code of mine, is my first attempt at inheritance. it is buggy and
I am sure there are few errors, it did not compile and I could not
find out why, please help.
thank you
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
using namespace std;
class Task {
protected:
string f_path;
short s_status;
string name;
string menu_item;
void load_status() {
string sf = f_path + name + "_s.txt";
ifstream in( sf.c_str() );
string s;
getline(in, s);
stringstream st(s.c_str());
st >> s_status;
}
public:
Task(string n, string mi) :
name( n ),
menu_item( mi ),
f_path( "../str1/status/" )
{
load_status();
}
void p_menu_item() const {
cout << menu_item << endl;
}
virtual void preform();
};
class Thr_task : public Task {
public:
Thr_task(string n, string mi) :
Task(n, mi) {}
void preform();
void pref_thr();
};
class No_thr_task : public Task {
public:
No_thr_task(string n, string mi):
Task(n, mi){}
void preform();
};
int main(){
No_thr_task nt1("sometask", "Taaask str1");
Thr_task t1("optm_upd", "Update and optimization");
nt1.p_menu_item;
t1.p_menu_item;
}
the errors relate to function overloading for the 2 lines above, and
also in relation to vtable and references.