Is there a reason we can not write in C++
class MyClass
{
public:
void MyClass::MyMethod(); // <----
}
it gives 'extra qualification' or some such compile error but is there a reason for that or it's just so happened?
Is there a reason we can not write in C++
class MyClass
{
public:
void MyClass::MyMethod(); // <----
}
it gives 'extra qualification' or some such compile error but is there a reason for that or it's just so happened?
Because that's the syntax for declarations; they declare an unqualified name to have a particular meaning within the scope of the declaration.
If a scope qualification were allowed, it would always be either redundant (specifying the current scope) or wrong (since you can't declare something in another scope).
The reason is that it is illegal syntax. Besides, why would you need to add a redundant extra qualification?
The member function is being declared in the context of the class definition, explicitly qualifying it as a member function of that class is unnecessary - and it compromises readability.