C ++ primer notes (5)

Source: Internet
Author: User

class sales_item
{< br> Public:
sales_item (void);
~ Sales_item (void);
PRIVATE:
string ISBN;
unsigned units_sold;
double revenue;
};
these operations and data are part of the class, also called a member of the class.
an operation is called a member function, and data is called a data member.
there is a very important difference between defining variables and defining data members: Generally, Class Members cannot be initialized as part of their definition. When defining a data member, you can only specify the name and type of the data member. The class does not initialize data members when defining data members in the class definition, but controls initialization through a special member function called constructor.

if you use the class keyword to define a class, all members are implicitly specified as private by default. If you use struct to define a class, the default value is public.
when a String object and a string nominal value are connected together, the plus and minus operators must have at least one string type.
A Vector Template rather than a class
vector V1; --------------------- an object whose vector type is t is saved.
vector V2 (V1); ---------------- V2 is a copy of V1.
vector V3 (n, I); ---------------- V3 contains n elements whose values are I.
vector V4 (n); ------------------ V4 contains N copies of elements whose values are initialized.
An important attribute of a vector object (and other standard container objects) is that it can efficiently add elements at runtime.
C ++ Program is a preferred choice! = Instead of <.
the iterator is a data type that checks elements in a container and traverses elements.
the iterator provides a more generic method than subscript operations: All standard library containers define the corresponding iterator type, and only a few containers support subscript operations.
vector :: iterator ITER;
const_iterator can only be used to read elements in the container, but cannot change its value.
distance between two iterators of iter1-iter2

Standard Library bitset class -------- simplifies bit set Processing
# Include <bitset>
Using STD: bitset
Bitset <32> bitvec; // 32 bits, all zero
Bitset <n> B; // B has n digits, each of which is 0.
Bitset <n> B (U); // B is a copy of the unsigned Long U.
Bitset <n> B (s); // B is a copy of the bits contained in String object S.
Bitset <n> B (S, POs, n); // B is the n-bit copy starting from position POs in S.
Use a String object to initialize a bitset object
String strval ("1100 ");
Bitset <32> bitvec4 (strval); // The first and second bits are 0, and the second and third bits are 1.

The string object and the bitset object are converted in reverse direction: the rightmost character of the string object is used to initialize the low-level bit of the bitset object.


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.