Why is the class keyword used in this code?

The following is part of the C ++ parser for simple arithmetic using the Composite pattern.

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> // abstract base class E class E { public: // pure virtual member function // = 0 means no implementation, only type virtual int eval() = 0; // virtual destructor virtual ~E(); }; // derived class for plus tree nodes class plus : public E { class E *e1; class E *e2; public: plus(class E *e1, class E * e2) { this->e1 = e1; this->e2 = e2; } ~plus(); int eval(); }; 

I don't understand what plus(class E *e1, class E * e2) does plus(class E *e1, class E * e2) . If E is a class, then of course it doesn’t need to have a prefix with the class keyword, which, in my opinion, is used only to define new classes? Why is the class keyword used in a function parameter?

Also, when I remove the class keywords, to get the following class definition:

 class plus : public E { E *e1; E *e2; public: plus(E *e1, E * e2) { this->e1 = e1; this->e2 = e2; } ~plus(); int eval(); }; 

The code (I mean that all the code with all the seemingly unnecessary occurrences of the class keyword is deleted, and not just the snippet provided by me here) is still compiled and builds and runs as usual. What is the reason for using the class keyword here?

+5
source share

Source: https://habr.com/ru/post/1271674/


All Articles