Job hunting C ++ Review (1)

Source: Internet
Author: User

Finding a good job makes your life happy. I want to start looking for a job. I will review C ++.

 

 

Book: Essential C ++

 

(1) What are the consequences of not adding using namespace STD?

Basicio. cpp: 24: Error: 'string' was not declared in this scope
Basicio. cpp: 26: Error: 'cout' was not declared in this scope
Basicio. cpp: 26: Error: 'endl' was not declared in this scope

 

(2) How to initialize variables in C ++?

Class mysum {<br/> Public: <br/> mysum (int A, int B); <br/> int getsum (void); <br/> int * ref; /* ref to a global value */<br/> PRIVATE: <br/> int sum; <br/>}; </P> <p> int main () </P> <p >{</P> <p> int A (12);/* equivalent to a = 12 */<br/> mysum summer (1, 2 ); /* You cannot directly assign values. Use the constructor */<br/> mysum summer2 = summer;/* implicitly call mysum: mysum (const mysum &) */</P> <p >}</P> <p> initobj. CPP: In function 'int main () ': <br/> initobj. CPP: 47: Error: no matching function for call to 'mysum: mysum () '<br/> initobj. CPP: 31: Note: candidates are: mysum (INT, INT) <br/> initobj. CPP: 23: Note: mysum (const mysum &) <br/>

 

(3) What are the initialization methods of class string?

 

 

 

(4) memory <,> stream Operator Method

According to the general oral order, "Left and Right", "read and write", the Order corresponds to, the left corresponds to read, and the Right corresponds to write.

 

(5) the meaning behind the = assignment in C ++

1. Simple assignment

2. automatically call copy constructor implicitly

3.

 

(6) Meaning of = in C ++ under different circumstances

 

(7) vector Initialization

Only an existing element can be indexed using the subscript operator. When values are assigned through subscript operations, no elements are added.

 

# Include <iostream> <br/> # include <vector> </P> <p> using namespace STD; </P> <p> int main () <br/>{< br/> vector <int> seq (12); <br/> seq [11] = 11; <br/> cout <seq [11] <Endl; <br/> seq [2, 9002] = 12;/* disaster! Use seq. push_back () instead */<br/> cout <seq [9789] <Endl;/* disaster! */<Br/>}

 

(8) const

// There is no syntax problem, but the const modifier aims to say that member variables cannot be modified in the Val () function. In general, Val () the returned _ Val cannot be modified. Since there is no const modifier before the function, _ Val is actually open to the outside.

Myclass & Val () const

{

Return _ Val;

}

 

// Correct statement:

Const myclass & Val () const

{

Return _ Val;

}

 

// The most perfect definition method:

Class val_class {

Const myclass & Val () const {return _ Val ;}

Myclass & Val () {return _ Val ;}

};

 

Void sample (const val_class * PBC, val_class & RBC)

{

PBC-> Val (); // call const

RBC. Val (); // call non-const

}

 

 

The mutable modifier can be used to break through the unchangeable restrictions of Const. For example, mutable int _ next;

 

 

(9) special characteristics of post ++ overload

In order to distinguish it from the front ++, the reload Declaration of the rear ++ can be modified. A redundant int is added to the parameter table, which is a special case:

Inline myobject & operator ++ (INT ){}

 

 

 

(10)

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.