Why is C ++ an extra method not allowed?

Is there a reason why we cannot write in C ++

class MyClass { public: void MyClass::MyMethod(); // <---- } 

it gives an “extra qualification” or some such compilation error, but is there a reason for this or did it just happen?

0
source share
2 answers

Because the syntax for declarations; they declare an unqualified name with a specific meaning as part of the declaration.

If the qualification of a region is valid, it will always be either redundant (indicating the current region) or incorrect (since you cannot declare something in another region).

+6
source

The reason is that this is illegal syntax. Also, why do you need to add redundant additional qualifications?

A member function is declared in the context of a class definition, without explicitly qualifying it as a member function of this class, and this jeopardizes readability.

+4
source

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


All Articles