C + + Primer Plus Sixth Edition notesThinking about Object declarationTransferred from: http://www.cnblogs.com/weiqubo/archive/2009/11/02/1930042.htmlWhat is the difference between the syntax for defining an object in C + + with parentheses and without parentheses?
#include
Class MyClass
{
Public
MyClass ()
{
Std::cout "Hello myclass!"
}
Public
void MyMethod ()
{
Std::cout "Hello
In the previous article (pointing to a function pointer example), we mentioned that there are two logically inconsistent syntax rules for using a function pointer to implement such an operation, and we will discuss it in the form of a question, in the past few days, I have read c primer plus and found a reasonable explanation. See the following example:
void ToUpper(char *);void ToLower(char *);void (*pf)(
I heard that the sixth version is the same as the fifth version, but I have an additional chapter C ++ 11. So, I 'd better study the fifth version.
There are errors in the same version 5, reference this errata: http://blog.csdn.net/woxing615701/article/details/3888576
C ++ primer plus (fifth edition) Chinese Version errata (constantly updated) This is an obvious error I found in C ++
18 key notes for C ++ Primer Plus 6th, primerplus
The following are the notes I have taken after reading C ++ Primer Plus version 6th, which can be used as a memorandum for future review.Note Section
Why is the const of C ++ better than that of C # define?
First, it can explicitly specify the type and has the t
"C Primer Plus" is really a great book, but the letter is not as good as the book, the author Stephen Prata may also hope that his readers can find a little bit of his inadvertently appear in the small mistake it! in the fifth edition of the book, chapter 17, "Advanced Data Representation", listing 17.2 shows the following code:#include #include #include #define TSIZE 45#define LEN sizeof (struct film)struc
Here are the notes I made after reading the 6th edition of C + + Primer Plus, as a memo to facilitate review later.Notes section
Why is C + + const better than C # # #?
First, it can explicitly specify a type and have type checking capabilities.Second, you can restrict a definition to a specific function or file by using a scope rule for C + +.Third, you can use the const for more complex ty
An error occurred in the sample program of the Chinese Version C Primer Plus Fifth edition, primerplus
The program with an error occurs on the ListItemCount () and Traverse () Functions on page 1 in Chapter 2.
The original book contains list. c defined by all functions as follows:
1 # include
However, the calling methods in film3.c are as follows:
1 Traverse (movies, showmovies); // pass the copy of the
next pair of numbers or Q to quit.QHope enjoyed this power trip--byte!9. Programming questions (question 7)1#include 2 3 DoublePowerDoubleNintPDoublePOW);4 5 intMain () {6 DoubleX,xpow;7 intexp;8 9printf"Enter A number and the positive integer power to which\n");Tenprintf"The number would be reduced. Enter Q to quit.\n"); One A while(SCANF ("%lf%d", x,exp) = =2){ -Xpow=power (X,exp,1); -printf"%.3g to the power%d is%.5g\n", X,exp,xpow); theprintf"Enter Next pair of num
C Primer Plus note4, primerplusnote4
Warning: implicit declaration of function 'pirntf' [-Wimplicit-function-declaration] |
This warning is caused by the use of a function without declaration: a function that is implicitly declared. Take a closer look at the warning and find that the printf () function is accidentally written as pirntf, so be careful when coding.
It does not matter if an error occurs
h:CIN >> ch;However, it ignores spaces, line breaks, and tabs. The following member function call reads the next character in the input (regardless of what the character is) and stores it in CH:Cin.get (CH);The member function calls Cin.get () to return the next input character----including spaces, line breaks, and tabs, so you can use it:ch = cin.get ();The Cin.get (char) member function call indicates that EOF has been reached by returning a bool value that is converted to false, whereas the
exception class will be thrown when the corresponding problem is found. A function can contain an exception specification that indicates an exception that might be thrown in the function, but c++11 abandons this functionality. An uncaught exception (an exception that does not match a catch block) terminates the program by default, except for exceptions that are not matched by any exception specification.The RTTI (run-time type information) feature allows the program to detect the type of an obj
base class member, even if two are private derivations. For example, suppose you want to be able to use Valarray's method min () and Max () through the student class, you can add the following using declaration in a common part of studenti.h:Class Student:private std::string, Private std::valarray{...PublicUsing std::valarrayUsing std::valarray};The using declarations above make valarraycout Note that using declarations use only member names--no parentheses, function feature labels, and return
can be shared between files, but the use of the keyword static-qualified function is internal, and is limited to the file in which it is defined.Dynamic memory allocation and deallocation is done using new and delete, which uses a free storage area heap to store data. Call new to consume memory, and call Delete to free memory. The program uses pointers to track the internal deposit elements.Name Space word order defines a named range in which an identifier can be declared. This is done to reduc
element at the same time using the specified variable. For example, for the following statement from listing 16.9 of the program:For_each (Books.begin (), Books.end (), Showreview);You can replace it with the following range-based for loop:for (auto X:books) Showreview (x);Depending on the type of book (vectorUnlike For_each (), a range-based for loop modifies the contents of a container, and the trick is to develop a reference parameter. For example, suppose you have the following function:voi
by the function, and the type.
Return statement: Returns a value from the called function to the calling function.
A class is a user-defined data type specification that describes in detail how information is represented and what operations can be done on the data. object is created from a class specification, just like a simple variable when the entity created by the data type description.C + + provides two predefined objects for processing input and output Cin and the cout , they are
namespace:Namespace{int ice;int bandycoot;}This is like following the using compiler directive, that is, the name declared in the namespace is potentially scoped to: from the declaration point to the end of the declaration area. From this perspective, they are similar to global variables. Because the namespace does not have a name, you cannot use the name in that namespace in a file other than the owning file. This provides a substitute for the static variables that are linked internally.34. Wh
. For a base class, you should provide a virtual destructor, even if it does not require a destructor.28. Constructors, destructors, and assignment operators cannot be inherited.29. You can assign a derived class object to a base class object, but at this point the assignment operator is responsible only for the base class member.30. The answer to the question "whether a base class object can be assigned to a derived class object" is "maybe". If a derived class object contains a constructor that
functions, and their overloaded versions.The prototype and definition of an explicit materialization should begin with templateMaterialization takes precedence over regular templates, rather than template functions over materialization and general templates.19. To learn more about templates, you must understand the terminology instantiation and materialization P288.20. Including the function template in the code itself does not generate a function definition, he is just a scenario for generatin
The 2nd chapter begins to learn C + +1. Endl ensure that the output is refreshed before the program continues to run (it is immediately displayed on the screen), and that using "\ n" does not provide such a guarantee, which means that in some systems, it is sometimes possible to prompt after you enter information.2. Keywords and parentheses in C + + can add spaces or noreturn (0);return (0);int main ();int main ();are legal.But Return0, there must be a space in the middle.3. The statement statem
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.