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
into 3 categories:Non-template friends, friends themselves are not template functions, but only use the implicit instantiation of the template class as parameters.Constraint template friend, each materialization of a class obtains a matching friend, and the type of friend depends on the type of materialization. Declare a friend function template outside the class declaration.Non-constrained template friend, each materialization of a friend is all materialized friends of the class. Declare a fri
generates the executable file a.out:g++ Spiffy.cxxSome versions may require links to C + + libraries:g++ spiffy.cxx-lg++To compile multiple source files, simply place them all on the command line:g++ My.cxx Precious.cxxThis will generate a copy of the executable file named A.out and the two target code files my.o and PRECIOUS.O. If you subsequently modify one of the source code files, such as My.cxx, you can recompile using MY.CXX and PRECIOUS.O:g++ My.cxx PRECIOUS.O3.Windows command-line compi
One of the great features of C is that it allows us to control the details of the program. C's memory management system is an example of this control capability. It implements these controls by letting us decide which functions know which variables and how long a variable exists in the program.1. Storage classes and their descriptorsThe main definition: scope, link, and storage time. Other programming languages also have similar concepts. The C language defines 5 storage classes through these th
is passed as parameter, and the original data is processed directly. 3. Other three types of data processing featuresHere's a brief look at the other three characteristics of processing data: Union, enumeration, and typedef.A union is a data type that can store different types of data in the same storage space (but at different time). Each variable is "mutually exclusive"-the disadvantage is not enough "containment", but the advantage is that memory usage is more granular and flexible, but also
the conversion is that it converts the numeric values stored in the computer's binary format into a series of characters for easy display. The "transformations" here can be understood as "translations".The 4.4.4 section focuses on mismatched conversions, which involve a lot of computer knowledge at the bottom. In particular, parameter passing works: The computer places the value of the variable on the stack, but reads it according to the conversion descriptor.In addition, the printf () return v
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.