G
Gary Wessle
Hi
in the attempt below, I intend to use 2 derived classes whose objects
c'tor fires a base class method which build a string "main_menu" which
is a concatenation of the strings for each derived object c'tor
argument. ok, let me explain in a different language; but before, here
is the expected output
preform Thread task.
preform non-thread task.
why did not it happen?
thanks
// the code.
// task.h
#ifndef TASK_H
#define TASK_H
#include <string>
#include <vector>
class Task {
std::string main_menu;
public:
Task();
void mm_build(std::string);
void p_main_menu();
};
class Thr_task : public Task {
public:
Thr_task(std::string);
};
class No_thr_task : public Task {
public:
No_thr_task(std::string);
};
#endif
****************************************************************
//task.cpp
#include <sstream>
using std::stringstream;
#include <fstream>
using std::ifstream;
#include <iostream>
using namespace std;
#include "task.h"
/* the base class */
Task::Task(){
p_main_menu();
}
void Task:_main_menu(){
cout << main_menu << endl;
}
void Task::mm_build(string s){
main_menu + ".\n" + s;
}
/* the drived class 1 */
Thr_task::Thr_task(string n)
{
Task::mm_build(n);
}
/* the drived class 2 */
No_thr_task::No_thr_task(string n)
{
Task::mm_build(n);
}
****************************************************************
//main.cpp
#include <iostream>
using std::cout;
using std::endl;
#include "task.h"
int main() {
Thr_task t1("preform Thread task");
No_thr_task n1("preform non-thread task");
Task dummy;
}
in the attempt below, I intend to use 2 derived classes whose objects
c'tor fires a base class method which build a string "main_menu" which
is a concatenation of the strings for each derived object c'tor
argument. ok, let me explain in a different language; but before, here
is the expected output
preform Thread task.
preform non-thread task.
why did not it happen?
thanks
// the code.
// task.h
#ifndef TASK_H
#define TASK_H
#include <string>
#include <vector>
class Task {
std::string main_menu;
public:
Task();
void mm_build(std::string);
void p_main_menu();
};
class Thr_task : public Task {
public:
Thr_task(std::string);
};
class No_thr_task : public Task {
public:
No_thr_task(std::string);
};
#endif
****************************************************************
//task.cpp
#include <sstream>
using std::stringstream;
#include <fstream>
using std::ifstream;
#include <iostream>
using namespace std;
#include "task.h"
/* the base class */
Task::Task(){
p_main_menu();
}
void Task:_main_menu(){
cout << main_menu << endl;
}
void Task::mm_build(string s){
main_menu + ".\n" + s;
}
/* the drived class 1 */
Thr_task::Thr_task(string n)
{
Task::mm_build(n);
}
/* the drived class 2 */
No_thr_task::No_thr_task(string n)
{
Task::mm_build(n);
}
****************************************************************
//main.cpp
#include <iostream>
using std::cout;
using std::endl;
#include "task.h"
int main() {
Thr_task t1("preform Thread task");
No_thr_task n1("preform non-thread task");
Task dummy;
}