The path of C + + learning

Source: Internet
Author: User
Tags print object

August 23, 2016
Some time ago really dawned, the book read wrong, I look at the C + + prime plus look at the real uncomfortable, do not know what the book is writing.
August 28, 2016
Flash Another 4-5 days, really fast ah, found that the Visual C + + from the beginning to master the real book is simply rubbish in the best, what is called 14 hours of audio and video interpretation, I le a go, is to follow the book a word do not pull the reading, the key also read a typo, learning so learning ah, no homework skills not to practice! The key also wasted 2.5 hours of my time. Now I am going to follow the online study of Mu class (more than a sentence, now the garbage book how much?) ):

Starting August 29, 2016:
C-C Relationship: All C programs can be run in the C + + compilation environment.
C + + added bool (boolean type) more than C language
New Initial initialization method:

On-demand:

#include <iostream>#include <stdlib.h>using namespace STD;intMainvoid){cout<<"Please enter an integer:"<<endl;intx=0;Cin>>x;cout<<oct<<x<<endl;//Convert the integer to 8 binarycout<<dec<<x<<endl;//Convert the integer to 10 binarycout<//Convert the integer to 16 binarycout<<"Please enter a Boolean value (0/1):"<<endl;BOOLy=false;Cin>>y;cout<<boolalpha<<y<<endl;//boolalpha Represents a Boolean valueSystem"Pause");return 0;}


Can not help hooves, out of the results: so that it will be 8, 10 binary, 16 binary between the free conversion.
C + + namespaces: Define namespaces with a name row name namespace

:: Indicates that the x in the A namespace is used.

August 30, 2016, I have not so much time, I looked at those courses, I want to speed up, and now I intend to master C + + at the speed of light, I have to make myself miserable, and then master OpenCV at least before the graduate student can do it face recognition simple things to make it.
Pointer:

Here is an example of a reference:

#include <stdlib.h>#include <iostream>using namespace STD;intMainvoid){intx =3;//define reference, Y is a reference to x    int&y=x;//Print values for x and y    cout<<x<<endl;cout<<y<<endl;//Modify the value of Yy =4;//Print the values of x and y again    cout<<x<<endl;cout<<y<<endl;system ("Pause");return 0;};

C + + keyword const: is used to control whether variables can change.
The relationship between const and a variable: that is, a variable becomes a constant.
The relationship between const and pointer type: const INT*P=NULL; and int const*p=null is exactly equivalent
const int *const p=null; const*const p=null with int, is exactly equivalent.
Function:
If the function is more important than the default value, the default value must be written to the right. Format:
Function overloading:
inline function: The keyword of an inline function: inline. :

C + + memory management
Request memory, use operator: new; free memory, use operator: delete
Request memory int*p=new int; free memory delete*p.
Request a block of memory: int *arr=new int[10]; free block memory: delete []arr;
Determine if the application memory failed: if (null==p) the memory allocation failed, when the request for memory needs to determine whether the memory request is successful, free memory needs to be set to a null pointer
Example:

#include <stdlib.h>#include <iostream>using namespace STD;intMainvoid){int*p=New int;//Request Memory    //Determine if the application memory is successful    if(null==p) {System ("Pause");return 0;//If the application fails we will exit ' If the application succeeds we'll assign p to the value of} *p= -;cout<<*p<<endl;DeleteP//Free memoryP=null;//Set the pointer to nullSystem ("Pause");return 0;};

Class
Object:

data member + member function = Completed class
Encapsulation: Just give the user some information they care about.
Access qualifier for Class (function: Select exposure) 1, public;2, protected;3, private
Instantiation, there are two ways, one is to instantiate from the heap, and one is to instantiate from the stack.
Instantiate from the stack:

To instantiate from the heap:

Instantiating from a heap requires freeing up memory and not using it in the stack.
Access methods for object members

Stack with "." Heap use "--"

If you are accessing an array inside a class, use the For statement
Operation of String:


Encapsulation of data:

#include <iostream>#include <string>using namespace STD;/** * Definition class: Student * data member: M_strname * Wrapper function for data member: SetName (), GetName () */classstudent{ Public://Define data member encapsulation function SetName ()    voidSetName (stringSTR) {m_strname=str; }//Define data member encapsulation function getname ()    stringGetName () {returnM_strname; };//Define student class private data member M_strnamePrivate:stringM_strname;};intMain () {//Use the New keyword to instantiate an objectStudent *str =NewStudent ();//Set the data member of the objectStr->setname ("MU-Class Network");//Use cout to print object str data members    cout<<str->getname () <<endl;//Release the memory of the object str and empty it    DeleteStr Str=null;return 0;}

Just finally got the reason, is because the input method, and then I changed the settings, each time the input process of the Bo people input method is English, so you can.
In-Class definition:

Out-of-class definitions:
There are two kinds of forms: 1, the same as the document definition;

2, sub-file definition outside the category

First define a header file (. h file) and then use it in another CPP file.
Memory 5 districts divided by use:
The feature of the stack area is that the memory is allocated and controlled by the system. Heap area, using Delete to recycle
Defines a class that does not consume memory until the class is instantiated. Initialization of an object: There are two types, with and only one initialization, and based on conditional initialization
Constructors: Constructors are called automatically when an object is instantiated. The constructor has the same name as the class, and the constructor does not return a value. Constructors can be overloaded.

The path of C + + learning

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.