C++ Error - Class related

Sep 6, 2019 at 4:14am
Hey guys just writing simple code to learn how things work with classes.

I normally split everything into header files but for the sake of learning I did everything in main.

I get a error in my code: “expects class name before token : “ - Can anyone help on what is wrong and how to fix?




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
39
40
41
42
43
44
45
46
47

#include <iostream>
using namespace std;


class Parent
{
    public:
    virtual void print()
    {
        cout << "Parent Prints" << endl;
    }
    void show()
    {
        cout << "Parent Shows" << endl;
    }
};



class Child: public: Parent
{ 
    public:
    void print()
    {
        cout << "Child Prints" << endl;
    }
    void show()
    {
        cout << "Child Shows" << endl;
    }
};




int main() 
{
	Parent John;
	Child Ben;
	Ben.show();
	return 0;
}



Sep 6, 2019 at 4:24am
Line 21:

class Child: public Parent
Topic archived. No new replies allowed.