16th chapter template and generic programming
1
2 function templates
Template
int compare (const T &v1,const t &v2) {}//template parameter cannot be empty
3 class Templates
Template
Class queue{
Public
Queue ();
Private
//
}
4 non-type template
The list container corresponds to a list of common data structures. The list container supports fast random inserts, deletes, but does not support fast random access elements; This is not the same as the vector container, vector containers do not
Two-way circular chain list is based on the two-way linked list of the implementation, and the two-way linked list of operations, the only difference is that it is a circular list, through each node of the two pointers to the knot together to form a
When using iterator traversal, delete one of the problems, the result is that the deletion of one can not be used since the increase
C + + vector traversal Delete element
has been not familiar with the vector deletion operation, is now sorted out.
There are four ways to return string functions in C + +:
1. Using heap space, return the heap address of the application, and pay attention to releasing 2. The function parameter passes the pointer, which returns the pointer 3. Returns the static
First you need to have #include this header file because it is the input output stream format control
Second such as Double sum=10; Cout
where Setiosflags (ios::fixed) do not write wrong it with the back of the Setprecision (1) used to control the
3 Resource Management
The so-called resource is, once used it, must return to the system in the future. The most commonly used resource in C + + programs is the dynamic allocation of memory (if you allocate memory but never return it, resulting in
The following is a personal understanding and is for informational purposes only.
what is a delegate.
First look at the simplest example of a delegate:
Namespace DelegateTest
{public
delegate void Messagedelegate (string name);
Class
In the process of using cocos2d-x, want to calculate time difference, such as Touchbegin and touchend click Time difference, need to get the current times, this time is usually used to obtain, return unit is time_t on the iOS platform looked down,
Due to the recent development of game find Road A * is used very frequently. So it's a logical bottleneck. C # is one times slower than C + +. So decide on C + +. This is an optimization. haha.
On vs VC + +. Sub-managed and unmanaged mode. Managed
has been on C + + DELETE and delete[] The difference is not very understanding, today encountered, online check, came to the conclusion. Make a backup to avoid loss.
C + + tells us to use delete[when retrieving the memory space of a single object
In this paper, the anonymous method in C # is described in detail, and the examples are illustrated. Now we will share it with you for your reference. The specific analysis is as follows:
First, the anonymous method in C # was introduced in c#2.0,
Compiler uses mingw32-g++ c++11, editor for CodeblocksIf a class wants other classes or functions to be able to access non-public members of the class, then you can use the friend method.
friend function:If you want a non-member function to
The purpose of overloaded operators:
The operations object for predefined operators in C + + is limited to basic built-in data types
Most of the time we need to do similar operations on our similar types, and this time we need to redefine the
1. Introduction
Virtual functions are the mechanisms used in C + + to implement polymorphism (polymorphism). The core idea is to access the function defined by the derived class through the base class. Let's say we have the following class hierarchy:
a topic in the book, Rubik's Cube Matrix, a line of elements added to a column of elements and the same size, the diagonal is the same as the beginning of a freshman will not write, Baidu also did not find.
Later,
Header file has an important function of rand (), which can be used as a random number generator.
Now I want to generate a random number, I use the following program:
#include
#include
using namespace std;
int main ()
{
cout
Here's the
After learning C + + basic knowledge, now learning C # is a lot simpler, but still a little different, such as C # two-dimensional array of definitions, declarations are different.
Here's a look at what's different:
Using System;
Using
1, the definition of the destructor functionDestructors (destructor), in contrast to constructors, perform destructors automatically when an object ends its lifecycle (for example, the function where the object is called) is completed. Destructors
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