Creating Simple Classes (C++)

Hello experts! :) Our teacher told us to make something like:

---------------------------->Arrow Release
------------> Ranged -->
---------------------------->Flamethrower
Attacks-->
---------------------------->Punch
------------> Melee -->
---------------------------->Kick

As you can see, he wants us to make seven classes which consist of the main idea (Attacks) then split attacks into two classes (Ranged and Melee) then split each of them into two more classes (Ranged: Arrow Release and Flamethrower, Melee: Punch and Kick) which total seven classes in all. Can someone please help me make these seven classes into one single .cpp file? Cause I tried searching youtube videos and cplusplus tutorial yet I still can't grasp it for some reason...
Well if the don't need to have any functions this would be pretty straight forward

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class attacks{

};

class ranged : attacks
{

};

class melee : attacks
{

};

class arrowRelease : ranged
{

};

class flamethrower : ranged
{

};

class punch : melee
{

};

class kick : melee
{

};

int main(){

return 0;
}


Oh thank you very sir/miss sumsar! :) But just our of curiosity, how would I do it with functions, if you don't mind? :) Thanks!
depends on what you should use it for. if you want on function that every class has you just make a public function in the attack class like so

1
2
3
4
5
6
7
8
class attacks{

public:
    void attack(){
          cout << "Base Attack!";
     }

};


I would recommend that you read this http://www.cplusplus.com/doc/tutorial/inheritance/
Last edited on
Topic archived. No new replies allowed.