If the method declaration does not use types declared in the class, for example, the type of the return value, then it does not matter where the method is declared.
Otherwise, if the declaration of the method depends on declarations of other types within the class, then an error may occur.
For example, the compiler will throw an error for this class definition
struct A { B f(); struct B {};
because type struct B used in the declaration of the member function f until the declaration of the structure.
source share