A destructor is the inverse function of a constructor. They are called when the object is destroyed (disposed). The function is specified as a destructor of the class by placing a tilde (~) in front of the class name. For example, declare a
The const in C + + can be used to modify variables, functions, and have different meanings in different places, as summarized below.
The semantics of the const
The purpose of const in C + + is to guarantee the constant nature of objects through
Storage area of C language Program
C Language Program after the compilation-link, will form a unified file, it consists of several parts, in the program run will produce several other parts, each part represents a different storage area:
Snippet
Problem:After converting std:string to char* from a C + + file, the char* containing the IP address needs to be extracted from the IP address in the string char*;
Solution:1. Solution Idea:The maximum IP address is 12 characters + 3 periods = 15
C + + file stream classes and file stream objectsA file stream is a data stream that takes an external memory file as an input and output object. The output file stream is the data flowing from memory to the external memory file, and the input file
The constructor of a base class cannot be inherited, and when a derived class is declared, the initialization of inherited member variables is also done by the constructor of the derived class. So when you design a constructor for a derived class,
Sometimes, there are two or more classes that have the same functionality, just different data types, as the following statement declares a class:
Class Compare_int
{public
:
Compare (int a,int b)
{
x=a;
y=b;
}
int Max ()
C + + Object pointersPointer to Object
When an object is created, the compilation system allocates a certain amount of storage space for each object to store its members. The starting address of the object space is the pointer to the object. You
C + + destructor
When an object is created, the system automatically calls the constructor to initialize the work, as well as the system automatically calls a function to clean up when the object is destroyed (for example, the various resources
The meaning of the const and volatile is:
(1) The section of this procedure can not be modified, any changes are illegal, or at least careless, the compiler should error, to prevent such carelessness;(2) Another program segment is completely
C language Accept () function: Accept socket connectionheader file:
#include #include
To define a function:
int accept (int s, struct sockaddr * addr, int * Addrlen);
Function Description: Accept () is used to accept
C language Fgetgrent () function: Reading group format functions
Header file:
#include #include #include
To define a function:
struct Group * getgrent (FILE * stream);
Function Description: Fgetgrent () reads a row
I. Basic knowledgeHow pointers and references are declared:Declaration pointer: char* PC;Declaration reference: Char c = ' A 'char& rc = c;
The difference between them:① from the perspective of the phenomenon, the pointer can change the value it
C + + vector usage
The built-in array of C + + supports the mechanism of the container, but it does not support the semantics of container abstraction. To solve this problem, we implement such a class ourselves. in standard C + +, the container
Copy Code code as follows:
Area Formula S = (A+B+C)/2 areas = sqrt (S * (s-a) * (s-b) * (s-c));
Small job to find the area of the triangle
int check (double a);int Check2 (double A, double b, double c);
#include #include int main
The object is not suddenly established, and the object must be created at the same time as the parent class and the object contained therein. C + + follows the following order of creation:
(1) If a class is specific to the base class, the default
I. Generating random numbers without a specified rangeWith the function rand (), the function prototype is int RAnd (), no parameters. A whole number between 0~rand_max is generated at this time. The size of the Rand_max can be viewed in the Include
Copy Code code as follows:
#include
typedef int datatype; /* Assume that the type of the linear table element is an integral type * *
#define MAXSIZE 1024/* assumes that the maximum length of the linear table is 1024*/
# define n 100/*
This article illustrates the difference between the methods used by sprintf in C + + and printf. Share to everyone for your reference. The specific analysis is as follows:
First, we'll look at the MSDN prototype and the sprintf prototype
Copy
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.