precautions are summarized above, which should be kept in mind because the compiler is unaware of these rules and therefore cannot discover errors).* For all Class members assigned by new when pointing to memory, delete should be used in the class's destructor, which frees the allocated memory.* If the destructor frees memory by using delete on pointer class members, each constructor should use new to initialize the pointer, or set it to a null pointer.* You should define a copy constructor tha
function, use the parse operator (::) to identify the class to which the function belongs;* Class methods can access the private components of a class.For example, the function header of the update member function is as follows:void Stock::update (double price)Example: implementation of a classProgram Listing 10.2 Stock00.cpp//Stock00.cpp--Implementing the Stock class//version xx#include #include"stock00.h"voidStock::acquire (ConstSTD::string Co,LongNDoublePR) { Company=Co; if(N 0) {Std::cout"N
automatically.Destructors complete cleanup work, so it's actually useful. Abuse, if the constructor uses new to allocate memory, the destructor uses Delete to free the memory.Destructor Prototypes:~stock ();destructor Definition:Stock::~stock (){cout }When a destructor should be called is determined by the toilet, and usually should not be called in code to call the destructor.If you create a static storage class object, its destructor will be called automatically at the end of the program.If y
member function by using the member operator period: Mr_object.try_me (). In OOP, this function call is referred to as sending the Try_me message to the Mr_object object. When a class data member is referenced in the Try_me () method, the corresponding data member of the Mr_object object is used. Similarly, the function call I_object.try_me () accesses the data member of the I_object object.If you want the member function to operate on more than one object, you can pass the extra object as a pa
Virtual functions of C ++ Primer Plus learning notes
There are two types of C ++ polymorphism: static polymorphism and dynamic polymorphism. Function overloading and operator overloading are the specific manifestations of static polymorphism. Dynamic polymorphism is the object for dynamically determining the operation during the program running. It is implemented through virtual functions;
1. Concepts of v
performed)
int type The return value of the function when it reaches EOF
istream (false after bool conversion)
eof
After EOF is detected, CIN sets two bits (Eofbit and Failbit) to 1, which can be cin.eof () to see if Eofbit is set, and Cin.fail () can see if Eofbit or Failbit is set
The IStream class provides a function that converts a IStream object to a bool value, which is automatically called when Cin appears where the bool value is now
characters from the streamGcount ()Putback () inserts a character into the beginning of the input stream, reading is the first character15. File input and outputTo add a header file FStreamTo write to a file1. Create a Ofstream object2. Associate the object with a specific file3. Use the Fout in a way that uses coutOfstream Fout;fout.open ("Hjq.txt");Read file1. Create a Ifstream object2. Associate the object with a specific file3. Use fcin in a way that uses CINLast Close Fout.close ()16. Crea
Iostream contains two basic types: IStream and Ostream.The standard library defines 4 IO objects: CIN, cout, Cerr (output warning and error message), clog (general information when the output program runs).Writing data to a streamsuch as:std::coutWhere the "must be an Ostream object, and the operand on the right is the value to be printed. Note: The second operator prints Endl, which is a special value called an operator. The effect of writing it is to end the current line and to brush the conte
Learning Summary1. If...else ... Semantically it can be used, and other languages are not worse, just remember, one of the furthest distances in the world: I walk if you go else.2, according to individual years of programming experience, too many if...else ... Nesting increases the readability and difficulty of maintaining code. Personally think the code is best not more than three layers if...else ... Nested, otherwise it is best to use a Boolean control process.3, logical operator precedence:!
represents a name for the requested memory space. Used to represent the value stored by the storage space.Carrots is a variable, that is, the value can be changed.2, line 12th carrots = 25; is an assignment statement that assigns the 25 token to the memory space stored by the carrot. There is a connection assignment concept, such as: A=b=c=3, which assigns 3 to C, assigns the value of C to B, and assigns the value of B to a. is assigned from right to left.3, line 17th carrots = carrots-1; Repre
preprocessor to add the contents of the iostream file to the program. This is a typical preprocessor operation: Replace or add text before the source code is compiled.This raises a question: Why add the contents of the iostream file to the program? The answer involves communication between the program and the outside world. Io in iostream refers to input (information entered into the program) and output (information emitted from the program). The input/output scheme for C + + involves multiple
function declares a parameter as a reference or pointer to a const, the parameter cannot be passed to another function unless the latter ensures that the parameter is not modified.40 . What cannot be inherited? constructors, destructors, assignment operators, friend functions.41. can I assign a base class object to a derived class object ? OK!! ① derived classes have a transform constructor: B (const A ), the conversion constructor can accept a type as a base class parameter and other parameter
:\n"); AboutCh=GetFirst (); $ } - - - } A + intGetFirst (void){ the intch; -Ch=GetChar (); $ while(GetChar ()! =Ten) the return 0; the returnch; the}Operation Result:Enter the operation of your choice:A. Add B. SubtractC. Multiply D.divideQ. QuitFPlease enter a right choice:DEnter First Number:QQQQQQ is a number.Please enter a number.such as 2.5, -1.78E8, or 3:1Enter Second number:0Enter a number other than 0:11/1=1.0"C-language learning", C
: Network Disk DownloadThis book is the prestigious C + + Classic tutorial, the content of C + + master Stanley B. Lippman Rich practical experience and the C + + Standards Committee, the former head of Josée Lajoie to the C + + standard in-depth understanding of the perfect combination, has helped countless programmers around the world to learn C + +. A comprehensive and authoritative description of C + + 's basic concepts and techniques, the emphasis on modern C + + programming style makes thi
The first few chapters are relatively simple, so just record the uniqueness.C + + adds the way {} initializes the variable, omitting the = sign so that all types can be initialized in the same way, and that initialization does not allow narrowingThe cout and cin,wchar_t with respect to char have wcout and wcin.The character constants of the wchar_t are prefixed with l, and their length and symbol characteristics are determined by the implementation.c++11 new char16_t (prefix u = character consta
pointer94Finout.write ((Char*) AMP;PL,sizeofPL) //prevent program interruption too late to send out data the if(Finout.fail ()) the { theCerr "Error on attempted write\n";98 exit (exit_failure); About } - 101 //Show revised file102CT =0;103FINOUT.SEEKG (0);//then output everything, position the pointer with the start position104cout "Here is the new contents of the"file the"file:\n";106 while(Finout.read (Char*) AMP;PL,sizeofPL))107 {108cout ": "": "1090) A) pl.population
answer to its calling function.#include 13. The following is a two function prototype:void Show (double ar[], int n); n is the number of elementsvoid Show2 (double ar2[][3], int n); n is the number of rowsA, write a function call to pass the compound text containing the values 8, 3, 9, and 2 to the function shows ().b, write a function call to pass a compound literal containing 2 rows and 3 columns of value to the function Show2 (), where the first behavior is 8, 3, 9, and the second behavior i
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.