C + + fundamentals (using)

Source: Internet
Author: User

Using:

1. introducing namespaces in the current file

???? using namespace Std;

2. using a using declaration in a subclass to introduce a base class member name (see C + + primer)

???? concrete Function embodies :

???? (1). Remove member protection or privatization restrictions due to inheritance introduce a base class member into the corresponding access control area of the derived class

???? Class Base {
???? Private:
???????? std::size_t size () const { return N;}
???? Protected:
???????? std::size_t N;
????};
???? Class Derive: private Base {

???? Public :
???????? using base:size;???????????? // user and in-class access
???? Protected:
???????? using base:n;???????????????? // in-class access
????};

???? (1). derived class to reload base class members ( normal , If the derived class requires overloading, you need to override the base class function for each derived class

???? class Base {
???? Public:
???????? std::size_t size () const { return 1;}

???????? std::size_t size (int n) const { return N;}
????};
???? Class Derive: public Base {

???? Public :

???????? using Base : size;???????????????????? // Get the base class all overloaded versions of this function
???????? std::size_t size (float N) Const { return N }????????????
????};

C + + fundamentals (using)

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.