[C + +] object oriented (polymorphic)
1. Understand polymorphism
(1) Concept of polymorphism
1. Determine the specific target of function call according to the actual object type; 2. The same call statement has many different manifestations in actual operation, which is polymorphism. The same statement has many forms. Overloads of functions and operators are polymorphic. 3. I ...
Posted by Mathy on Sat, 30 Oct 2021 14:09:54 +0200
Classic examples of branch and loop statements
1, Write code to output three integers from large to small
Method 1
#include<stdio.h>
int main()
{
int a = 0;
int b = 0;
int c = 0;
scanf("%d %d %d", &a, &b, &c);
if (a > b && b > c)
printf("%d %d %d", a, b, c);
else if (a > c && c > b)
printf("%d %d %d", a, c, b);
else if (b ...
Posted by jollyjumper on Sat, 30 Oct 2021 10:13:46 +0200
Sword finger offer: 37 the first common node of two linked lists (note)
Enter two linked lists and find their first common node.
As shown in the following two linked lists:
The intersection begins at node c1.
Example 1:
Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3Output: Reference of the node with value = 8Input explanation: the value of intersection no ...
Posted by damonlee on Sat, 30 Oct 2021 09:43:10 +0200
Guess Person *ptr=nullptr; ptr->dowork(); Will the program collapse?
At work today, I wrote the code happily. A colleague ran over excitedly and said, "ah yuan, look at your enterprise wechat.". Me: "what's the situation? Do you want a raise?" Colleague: "will salary increase be said on enterprise wechat?" Me: "Okay" When I opened enterprise wechat, it turned out to be an ...
Posted by stormcloud on Fri, 29 Oct 2021 13:39:28 +0200
C++11 thread library thread stop
In this article, we will discuss how to stop and terminate a thread under C++11.
Why doesn't C++11 directly provide a method to stop threads? This is because some resources may need to be released and closed before the thread stops, such as:
The thread has acquired the ownership of the lock. Who will be responsible for releasing the ownership ...
Posted by akravets on Fri, 29 Oct 2021 04:32:19 +0200
Creative mode - Factory mode (simple factory mode, factory method mode, abstract factory mode)
Statement: This blog refers to the Chinese Language C website: C Language Chinese Network Connection
The main record is learning the following: 1. Simple Factory Mode II. Factory Method Mode 3. Abstract Factory Mode Each main point consists of the following two parts: (1) Basic concepts and model structure (including some NOUN explanations, mo ...
Posted by revez2002 on Thu, 28 Oct 2021 19:37:13 +0200
Memory layout of [CPP] class
This article can solve the following three problems:
How are the member variables of a class distributed after inheritance in different ways?
Virtual function table and virtual function table pointer, position in executable file?
How does the content of the virtual function table of a class change after single inheritance, multiple inheritance ...
Posted by mark110384 on Thu, 28 Oct 2021 08:42:16 +0200
C++11~20 constant expression
C++98 Era
The C++98 compiler has a special preference for int constants because they are one of the few things it can directly recognize. Because of this limited capability, the compiler can pre determine the size of the array:
TEST_METHOD(TestConstVar)
{
//int n = 3;
const int n = 3;
int a[n] = { 0 };
Assert::AreEqua ...
Posted by dcace on Thu, 28 Oct 2021 06:20:18 +0200
[C + +] vector and high-precision calculation
vector
Luogu original topic https://www.luogu.com.cn/problem/P1009 This topic requires high-precision factorial writing, but I haven't learned it yet. I picked up all kinds of materials and online classes from the Internet and found that before learning high precision, I need to know the container vector.
What is a vector
vector is a sequent ...
Posted by erikwebb on Wed, 27 Oct 2021 16:39:31 +0200
C + + template preliminary
1. Generic programming
For example, how to realize the general function of exchanging 2 numbers?
void Swap(int x, int y)
{
int tmp = x;
x = y;
y = tmp;
}
void Swap(double x, double y)
{
int tmp = x;
x = y;
y = tmp;
}
Although function overloading can be implemented, there are several disadvantages:
Overloaded functions only have ...
Posted by gray_bale on Wed, 27 Oct 2021 08:56:02 +0200