In the other use of inline in the previous article, it is mentioned that the function implementation differs from the class definition in the class definition.
Now let's look at an experiment:
A.cpp:
[CPP]View PlainCopy
- #ifndef Test_h
- #define Test_h
- Class a{
- Public :
- int Fun (int x) {
- return (x*x+1000);
- }
- };
- #endif
- void TT ()
- {
- }
B.cpp:
[CPP]View PlainCopy
- Class a{
- Public :
- int Fun (int x);
- };
- void TT ();
- int yy ()
- {
- TT ();
- A;
- return A.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:
[CPP]View PlainCopy
- #ifndef test_h
- #define  TEST_H  
- CLASS A{  
- PUBLIC:  
- int fun (int x);
- };
- #endif
- int a::fun (int x) {
- return (x*x+1000);
- }
- void tt ()
- {
- }  
Compile a.cpp and b.cpp for A.O and B.O, respectively, to display the link successfully.
Thus, the reason for the first link error is obvious.
Conclusion:
A class member function in a class definition implements a file inner scope, whereas a class implementation outside of a class definition has a global scope.
http://blog.csdn.net/tobacco5648/article/details/7651408
C + + member function implementations differ from class definitions in class definitions (using g++ directly under Windows)