C + +: The difference between a member function implementation and an outside class definition in a class definition

Source: Internet
Author: User
Tags class definition

//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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.