Effective C + + clause 38

Source: Internet
Author: User

The terms of this section are relatively simple and popular means "there is one" and "is a" difference, and the difference between the application domain (application domain) and the implementation domain (implementation domain).
The following code:

1.

class Bird//鸟{public:    //............};class ostrich:public Bird//鸵鸟{public:    //............};

This code refers to the "is a" relationship, ostrich is also a bird, ostrich has a variety of bird properties.

2.

class Name{public:    //..............};class Person{public:    //.......private:    Name name;};

This code refers to the "have a" relationship, the name is a class, everyone has a name.

3.
Take a look at the examples in the book:

#include <iostream>#include <list>using namespace STD;Template<classT>classmyset{Private: list<T>MyList; Public:intSize ()Const{returnMylist.size (); }BOOLiscontained (T Element)Const{return(Find (Mylist.begin (), Mylist.end (), T)! = Mylist.end ()); }BOOLInsert (T Element) {if(! Iscontained (T)) {mylist.push_back (Element);return true; }Else{return false; }    }BOOLRemove (T Element) { list<T>:: Iterator Iter = Find (Mylist.begin (), Mylist.end (), T);if(Iter! = Mylist.end ()) {mylist.erase (Iter);return true; }Else{return false; }    }};

This is the embodiment of the implementation of the domain, we are programmed to choose the structure of our program function to serve, so we have to transform the existing structure to adapt to our needs. As above, the list structure may store the same elements, but the set class requires that the same elements cannot be stored, so in order for the list structure to serve our program, we define the list operation in the program to meet our needs.

Effective C + + clause 38

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.