//A.cppclassa{ Public: intFunintx) { return(x*x+ +); } }; voidtt () {}//B.cppclassa{ Public: intFunintx); }; voidtt (); intyy () {TT (); A; returnA.fun (3); }
Compile them and then link them separately:
A link error was displayed because a reference to A::fun (int) could not be found in B.cpp (B.O).
Change the a.cpp above to read as follows:
Class a{ public: int fun (intint A:: Fun (int x) { return (x*x+); } void tt () { }
Compile the a.cpp again without compiling the B.CPP,A.O and B.O after the link to display the link successfully.
Thus, the reason for the first link error is obvious.
Conclusion: the class member function in the class definition has a file inner scope, while the class implementation outside the class definition has some global scope.
C + +: member function implementation differs from class definition in class definition