Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » heirdom

This thread is locked; no one can reply to it. rss feed Print
heirdom
kosmitek
Member #8,151
December 2006

I have more complex classes, but I shortened it in order to it was better to be visible, because problem concerns heirdom only.

When I tried compile it I saw:
"55 C:\Documents and Settings\windowsXP\Pulpit\BezNazwy1.cpp base `player' with only non-default constructor in class without a constructor "

So something is wrong with constructor - I lower marked the line of code which she be lighted as wrong.

PS. I know that we don't heirdom constructor :P

1 
2class player
3{
4 private:
5 int money;
6 int health;
7 int weapon;
8 int power;
9
10
11 public:
12 player(int a, int b, int c, int d);
13
14
15 int change_money(int x);
16 int change_health(int x);
17
18
19 int see_money();
20 int see_health();
21
22
23};
24 
25 
26 
27 
28 
29 
30class monster
31{
32 private:
33
34 int money;
35 int health;
36
37 public:
38
39 monster(int a, int b);
40
41
42 int see_money();
43 int see_health();
44
45};
46 
47 
48 
49 
50 
51class better_player : public player
52{ <------------------------ this line of code is lightened
53 
54
55
56 public:
57 void function()
58 {
59 }
60};
61
62 
63 
64
65 
66 
67 player::player(int a, int b, int c, int d)
68 {
69 money=a;
70 health=b;
71
72 }
73
74
75
76
77 int player::change_money(int x)
78 {
79 money=money+x;
80
81 }
82
83 int player::change_health(int x)
84 {
85 health=health+x;
86
87 }
88
89
90
91 int player::see_money()
92 {
93
94 return money;
95 }
96
97 int player::see_health()
98 {
99
100 return health;
101 }
102
103
104
105
106 
107monster::monster(int a, int b)
108 {
109
110 money=a;
111 health=b;
112 }
113 
114int monster::see_money()
115 {
116
117 return money;
118 }
119
120
121int monster::see_health()
122 {
123
124 return health;
125 }

X-G
Member #856
December 2000
avatar

GET A C++ BOOK ALREADY. It will tell you all these things! You can't have a class (in this case better_player) with no explicit constructors that's inherited from a class with no default constructors!

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

kentl
Member #2,905
November 2002

You can download Thinking in C++, 2nd edition by Bruce Eckel for free. It might be a good read.

Richard Phipps
Member #1,632
November 2001
avatar

Can you really think in a programming language? I don't mean imagining how to solve a programming issue or problem by thinking of the code, but thinking in general? Life, and all that.. :o

Evert
Member #794
November 2000
avatar

Quote:

heirdom

The google term is "inheritance"

kentl
Member #2,905
November 2002

Quote:

Can you really think in a programming language? I don't mean imagining how to solve a programming issue or problem by thinking of the code, but thinking in general? Life, and all that.. :o

Apparantly Bruce Eckel can. And we could as well if we read his book. ;D

kosmitek
Member #8,151
December 2006

I use: constructor: "player() {};"
and now it works !! ;D;D

so now I have:

1class player
2{
3 private:
4 int money;
5 int health;
6
7
8
9 public:
10 player() {};
11 player(int a, int b);
12
13
14 int change_money(int x);
15 int change_health(int x);
16
17
18 int see_money();
19 int see_health();
20
21
22};

Steve Terry
Member #1,989
March 2002
avatar

Gasp! Could it ... no no ... could it really be possible kosmitek did something on his own? I can't believe it. Well I guess you don't need our help now, good luck on your next MMORPG project. Oh and by the way the whole point of inheritance you defeated by the way you wrote your classes. Again they do nothing you couldn't do with fewer lines of code in a single class or with C.

Sorry for the sarcasm... but DAMN man!

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Go to: