Rolf Magnus <ra******@t-online.dewrites:
Gary Wessle wrote:
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.
....
}
the errors
Which errors? Please always paste the original error message from your
compiler into the posting. You might not know what their meaning is, but
many people here do, so it make it easier to help you. Best is to also
directly mark the lines the error messages are referring to with a comment.
relate to function overloading for the 2 lines above, and
also in relation to vtable and references.
Well, you have three classes, and in each of them, a function preform() is
declared, but there is no implementation of any of those three functions.
Same for Thr_task::pref_thr().
well, I thought the virtual key word did just that, I don't want to
make it pure virtual (=0) for fear that I may need to create an
instance of the base, well, maybe I should try the pure virtual.
cd /home/fred/myProg/try/
make -k
g++ -gdwarf-2 -c -o main.o main.cpp
main.cpp: In function ‘int main()’:
main.cpp:80: error: statement cannot resolve address of overloaded function
main.cpp:81: error: statement cannot resolve address of overloaded function
make: *** [main.o] Error 1
make: Target `proj' not remade because of errors.
Compilation exited abnormally with code 2 at Fri Nov 10 05:16:48
the lines 80, 81 are
nt1.p_menu_item;
t1.p_menu_item;
and when I comment them I get:
cd /home/fred/myProg/try/
make -k
g++ -gdwarf-2 -c -o main.o main.cpp
g++ -Wall -gdwarf-2 -o proj handle.o main.o swi_board.o
main.o: In function `~Task':
/home/fred/myProg/try/main.cpp:17: undefined reference to `vtable for Task'
main.o: In function `~Thr_task':
/home/fred/myProg/try/main.cpp:52: undefined reference to `vtable for Thr_task'
main.o: In function `~No_thr_task':
/home/fred/myProg/try/main.cpp:61: undefined reference to `vtable for No_thr_task'
main.o: In function `Task':
/home/fred/myProg/try/main.cpp:39: undefined reference to `vtable for Task'
main.o: In function `No_thr_task':
/home/fred/myProg/try/main.cpp:64: undefined reference to `vtable for No_thr_task'
main.o: In function `Thr_task':
/home/fred/myProg/try/main.cpp:55: undefined reference to `vtable for Thr_task'
collect2: ld returned 1 exit status
make: *** [proj] Error 1
Compilation exited abnormally with code 2 at Fri Nov 10 05:18:27
here is the code again but with line numbers this time.
************************************************** **************
1 #include <string>
2 using std::string;
3 #include <sstream>
4 using std::stringstream;
5 #include <fstream>
6 using std::ifstream;
7 #include <iostream>
8 using std::cout;
9 using std::endl;
10
11 // #include "swi_board.h"
12 // #include "handle.h"
13
14 using namespace std;
15
16
17 class Task {
18
19
20 protected:
21 string f_path;
22 short s_status;
23 string name;
24 string menu_item;
25
26 void load_status() {
27 string sf = f_path + name + "_s.txt";
28 ifstream in( sf.c_str() );
29 string s;
30 getline(in, s);
31 stringstream st(s);
32 st >s_status;
33 }
34
35 public:
36 Task(string n, string mi) :
37 name( n ),
38 menu_item( mi ),
39 f_path( "../str1/status/" )
40 {
41 load_status();
42 }
43
44 void p_menu_item() const {
45 cout << menu_item << endl;
46 }
47 virtual void preform();
48
49 };
50
51
52 class Thr_task : public Task {
53 public:
54 Thr_task(string n, string mi) :
55 Task(n, mi) {}
56
57 void preform();
58 void pref_thr();
59 };
60
61 class No_thr_task : public Task {
62 public:
63 No_thr_task(string n, string mi):
64 Task(n, mi){}
65
66 void preform();
67 };
68
69
70
71
72
73 int main(){
74 // Handle ha; // control pointer to functions
75 // Switch sw(ha); // load the switches
76 // cout << "handle" << endl;
77 No_thr_task nt1("sometask", "Taaask str1");
78 Thr_task t1("optm_upd", "Update and optimization");
79
80 // nt1.p_menu_item;
81 // t1.p_menu_item;
82
83
84
85 }
86
************************************************** **************