
C++
包括模版,注意细节,各种方法
卷纸要用清风的
Environment.NewLine
展开
-
静态方法 static foo()
而在Python 3中,如果一个类的方法不需要self参数,不再需要声明为静态方法,但是这样的话只能通过类去调用这个方法,如果使用实例调用这个方法会引发异常。但通常建议通过类名来使用静态方法,因为静态方法只要定义了类,不必建立类的实例就可使用。在处理大量功能模块和多个代码文件时,静态方法能够组织不同的方法为一个单独的类,避免在不同程序文件中查找函数的麻烦。总之,静态方法因其独特的特性和优势,在编程中扮演着重要的角色,特别是在提高代码效率、可维护性和复用性方面。这些方法属于类本身,而不是类的某个具体对象。原创 2024-03-21 20:23:27 · 345 阅读 · 0 评论 -
C++ 单列模式
先暂时告一段落。原创 2024-03-20 12:32:44 · 134 阅读 · 0 评论 -
C++ 类构造函数 & 析构函数
析构函数会按照类的继承顺序从基类到派生类的顺序依次调用。析构函数会按照创建对象的顺序从最后创建的对象到最先创建的对象的顺序依次调用。析构函数会按照对象内部成员变量的声明顺序从最后声明的成员变量到最先声明的成员变量的顺序依次调用。int id;return id;showId();showName();bo.show();ao.show();return 0;原创 2024-03-19 00:39:32 · 522 阅读 · 0 评论 -
C++ 类访问修饰符
成员,这个成员只能被自己和友元访问了,所以第二类的派生类(第三类)就无法访问这个成员了。简言之就是看从自己的上一个基类是啥类型,成员只能被本类成员(类内)和友元访问,不能被派生类访问;三种继承方式,它们相应地改变了基类成员的访问属性。继承到第二类后,再由第三类继承第二类时,基类中的。成员可以被派生类访问。成员在第二类中变成了。原创 2024-03-18 23:33:46 · 442 阅读 · 0 评论 -
更安全的C gets()和str* 以及fgets和strcspn的用法
可以说全是错误首先char *str没有指向一个分配好的地址,就直接读入,危险ps:怎么理解是将一个存储在一个只读的数据段中字符串常量的首地址赋值给了尝试从标准输入读取一个字符串并存储在str指向的位置。但是,由于str没有被初始化为指向有效的内存,gets函数可能会尝试写入一个随机的内存地址,这会导致程序崩溃或更糟糕的后果。puts(str);试图打印从gets读取的字符串。但是,由于gets可能导致未定义行为,str指向的内容可能是不确定的,所以puts的行为也是不确定的。更糟糕的是,原创 2024-03-16 22:59:16 · 649 阅读 · 0 评论 -
C++ time
在C语言中,localtime是一个函数,用于将自1970年1月1日(UTC)以来的秒数(通常称为时间戳或Unix时间)转换为本地时间的struct tm格式。这个转换考虑了本地时区以及夏令时(如果适用)的影响。在这个示例中,time函数用于获取当前时间的时间戳,然后localtime将其转换为本地时间,并通过asctime转换为人类可读的字符串格式进行打印。函数返回一个指向struct tm的指针,该结构体包含了分解后的本地时间信息,如年、月、日、小时、分钟、秒等。原创 2024-03-16 18:22:56 · 735 阅读 · 0 评论 -
函数返回二维数组
在C语言中,函数不能直接返回二维数组,因为数组名作为函数参数或返回值时,会退化为指向数组首元素的指针。此外,C语言不支持返回局部数组的引用,因为局部数组在函数返回后其内存会被释放。原创 2024-03-15 01:02:24 · 1148 阅读 · 0 评论 -
数组指针的理解
说明这个指针指向了一个大小为5的数组。原创 2024-03-15 00:48:51 · 389 阅读 · 0 评论 -
C++ lambda函数个人理解
(3)-> return_type:->后面为lambda函数的返回类型,如 -> int、-> string等。一般情况下,编译器推出lambda函数的返回值,所以这部分可以省略不写。(1)[capture] :[]内为外部变量的传递方式,值、引用等,如下。(2)(parameters) :()内为形参,和普通函数的形参一样。*/ }:{}内为函数主体,和普通函数一样。及方便自己在函数内部定义函数。原创 2024-03-14 21:41:22 · 503 阅读 · 0 评论 -
C++ 类中static成员初始化
在C++中,你不能直接在类定义中初始化静态成员变量。你需要在类外部进行初始化。这是因为在类定义中,你只是声明了静态成员,而初始化涉及到存储分配,这通常在编译时不能决定。但是,这仍然是一个定义,而不仅仅是一个初始化。它告诉编译器这个定义应该在多个翻译单元中合并成一个。这与在类外部定义静态成员变量的效果相同,但是语法更简洁。原创 2024-03-14 20:12:54 · 855 阅读 · 0 评论 -
const成员函数 修改mutable修饰的值
register 用于定义寄存器变量,表示该变量被频繁使用,可以存储在CPU的寄存器中,以提高程序的运行效率。volatile 修饰符 volatile 告诉该变量的值可能会被程序以外的因素改变,如硬件或其他线程。static 用于定义静态变量,表示该变量的作用域仅限于当前文件或当前函数内,不会被其他文件或函数访问。// 定义变量 num,其值可能会在未知的时间被改变。// 定义指向常量的指针,指针所指的值不可修改。类型限定符提供了变量的额外信息,用于在定义变量或函数时改变它们的默认行为的关键字。原创 2024-03-14 18:38:13 · 451 阅读 · 0 评论 -
作用域解析运算符(Scope Resolution Operator)在C++中的用法和作用
【代码】作用域解析运算符(Scope Resolution Operator)在C++中的用法和作用。原创 2024-03-14 14:33:54 · 503 阅读 · 0 评论 -
C++ 类型转换 未解决
/ 常量转换,将const int转换为int。重新解释转换将一个数据类型的值重新解释为另一个数据类型的值,通常用于在不同的数据类型之间进行转换。静态转换通常用于比较类型相似的对象之间的转换,例如将 int 类型转换为 float 类型。常量转换用于将 const 类型的对象转换为非 const 类型的对象。C++ 中有四种类型转换:静态转换、动态转换、常量转换和重新解释转换。常量转换只能用于转换掉 const 属性,不能改变对象的类型。类型转换是将一个数据类型的值转换为另一种数据类型的值。原创 2024-03-14 13:34:12 · 422 阅读 · 0 评论 -
AVLTree ( C++ )
什么时候闲的再继续参考网址https://juejin.cn/post/6844903773756719112#include<cstdio>#include<iostream>using namespace std;typedef int elementType;struct AVLNode { int depth; AVLNode* parent; AVLNode* leftChild; AVLNode* rightChild;原创 2021-03-01 21:26:32 · 106 阅读 · 0 评论 -
C++ #016 回文串的q次询问 02
预处理标志重捕法???https://ac.nowcoder.com/acm/contest/15084/B#include<iostream>#include<cstdio>#include<string>#include<cstring>using namespace std;int main() { string s; cin>>s; int len=s.size(); bool a[len原创 2021-04-17 18:55:45 · 104 阅读 · 0 评论 -
C++ #015 lvalue rvalue 02
lvalue : locator value;rvalue : rest value.原创 2021-03-23 21:33:43 · 93 阅读 · 0 评论 -
C++ #014 char[] length size char* string 02
#include<iostream>#include<cstdio>#include<string>#include<cstring>using namespace std;int main() {// string a;// cout<<"size = "<<a.size()<<endl;// cout<<"length = "<<a.length()<<原创 2021-03-15 21:57:18 · 175 阅读 · 0 评论 -
C++ #013 题目map与string 02
https://ac.nowcoder.com/acm/contest/12794/题目描述According to the national statistics, a teenager sends/receives 100+ text messages a day. Dr. Orooji’s teenage children are no exception but the problem is Dr. O (an old-fashioned, face-to- face communicato.原创 2021-03-15 20:38:51 · 133 阅读 · 0 评论 -
C++ #012 模板之简易vector 02
#include<iostream>#include<cstdio>using namespace std;template<typename T> class MyVector { T* head; int length; int size;public: MyVector(int setLength=50) { if(setLength>=0) { size=0;原创 2021-02-27 18:53:15 · 71 阅读 · 0 评论 -
C++ #011 模板 02
#include<iostream>#include<cstdio>using namespace std;template<typename T> void Swap(T& a, T&b) { T tmp; tmp=a; a=b; b=tmp;}int main() { int a=1, b=2; Swap(a, b); printf("a = %6d b = %6d\n", a, b原创 2021-02-24 23:29:49 · 110 阅读 · 0 评论 -
C++ #010 抽象类 02
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;class TwoDimensionalGraphics {public: virtual void showArea()=0;};class Triangle final: public TwoDimensionalGraphics { double原创 2021-02-24 23:10:21 · 75 阅读 · 0 评论 -
C++ #009 虚函数 02
#include<iostream>#include<cstdio>using namespace std;class Base {public: virtual void called() { printf("Base\n"); }};class Derived1: public Base {public: virtual void called() { printf("Derived_1\n");原创 2021-02-24 18:05:38 · 106 阅读 · 0 评论 -
C++ #008 运算符重载 02
#include<iostream>#include<cstdio>using namespace std;class Complex { double real; double imag; static int complexTotal;public: Complex(double setReal=0, double setImag=0); Complex(const Complex& demo); ~Compl原创 2021-02-24 17:31:54 · 81 阅读 · 0 评论 -
C++ #007 运算符重载 02
#include<iostream>#include<cstdio>using namespace std;class Clock { int hour; int minute; int second;public: void updateTime() { if(second>=60) { minute+=second/60; second%=60; }原创 2021-02-24 16:22:04 · 110 阅读 · 0 评论 -
C++ #006 运算符重载 复制构造函数的调用问题 三种情况 02
#include<iostream>#include<cstdio>using namespace std;class Complex { double real; double imag; static int complexTotal;public: Complex(double setReal, double setImag); Complex(); Complex(const Complex& demo);原创 2021-02-23 22:23:28 · 99 阅读 · 0 评论 -
C++ #005 继承 02
#include<iostream>#include<cstdio>using namespace std;class Base { int number;public: Base(int setNumber):number(setNumber) {} Base():Base(0) {} Base(Base& demo):Base(demo.number) {} ~Base() {} void show() const原创 2021-02-22 16:53:56 · 69 阅读 · 0 评论 -
C++ #004 继承 02
#include<iostream>#include<cstdio>using namespace std;class Base { int number;public: Base(int setNumber):number(setNumber) {} Base():Base(0) {} ~Base() {} void show();};class Derived: private Base { int sumber;原创 2021-02-21 22:44:49 · 86 阅读 · 0 评论 -
C++ #003 构造 02
小样例#include<iostream>using namespace std;class A{ int a; static int aCount;public: A(); A(int seta); A(A &demo); ~A(); void showA(); int getAcount();};int A::aCount=0;A::A():A(0){ cout<<"A()\n原创 2021-02-10 20:50:38 · 103 阅读 · 0 评论 -
C++ #002 构造 02
委托构造函数#include<iostream>using namespace std;class Clock{//可省略private int hour=0; int minute=0; int second=0;public: Clock();//默认构造函数 Clock(int setHour, int setMinute, int setSecond=1);//构造函数 void setTime(int setHour=0,原创 2021-02-09 20:47:35 · 110 阅读 · 0 评论 -
C++ #001 构造 02
#include<iostream>using namespace std;class Clock{//可省略private int hour=0; int minute=0; int second=0;public: Clock();//默认构造函数 Clock(int setHour, int setMinute, int setSecond=1);//构造函数 void setTime(int setHour=0, int set原创 2021-02-09 20:44:22 · 114 阅读 · 0 评论 -
堆排序 ( C++ )
#include<iostream>#include<cstdio>using namespace std;void heapjudge(int a[], int father, int length){ int tmp; if(father*2+2>=length) { if(a[father]<a[father*2+1]) { tmp=a[father];原创 2021-02-06 00:34:26 · 121 阅读 · 0 评论 -
C++ 继承 01
#include<iostream>using namespace std;class people{private: int age; int high;public: people(int a=19,int h=180):age(a),high(h) {} ~people() { cout<<"People was died"<<endl; } void show() {原创 2021-01-22 21:41:22 · 79 阅读 · 0 评论 -
C++ 模板 01
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;template<typename T>class man{ T age;public: man(T _age=0):age(_age) {} void show();};int main(){ man<int> a(18); a.show(原创 2021-01-22 21:43:00 · 72 阅读 · 0 评论 -
C++ 构造 01
#include <iostream>#include<stdio.h>using namespace std;class juxin{private: int chang,kuan;public: int zhochang(); int mianji(); void fuzhi(int a,int b); juxin(); juxin(int c,int k); juxin(double c,double k);原创 2021-01-22 21:40:23 · 82 阅读 · 0 评论 -
C++ STL 01
#include<iostream>#include<algorithm>#include<vector>#include<string>#include<sstream>#include<stdio.h>#include<string.h>#include<math.h>using namespace std;int main(){ vector<int> a;原创 2021-01-22 21:42:15 · 78 阅读 · 0 评论 -
线段树 ( C++ )
构建#include<iostream>#include<cstdio>using namespace std;typedef long long ll;struct T{ int num=0; int l=0; int r=0;};void build(int i,int l,int r,int data[],T tree[],int generation){ generation++; printf("%d : l =原创 2021-02-07 17:14:27 · 168 阅读 · 0 评论 -
快速幂 ( C++ )
#include<iostream>#include<cstdio>using namespace std;typedef long long ll;const int mod=1E7+2;ll fastPower(ll base, ll power) { ll ans=1; while(power>0) { if(power&1) { ans=ans*base%mod; }原创 2021-02-20 23:51:15 · 144 阅读 · 0 评论 -
cout 格式控制 ( C++ )
http://c.biancheng.net/view/275.html#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<iomanip>using namespace std;typedef long long ll;int main() { //TODO int a.原创 2021-08-20 22:20:02 · 167 阅读 · 0 评论 -
自适应希普森 ( C++ )
https://vjudge.net/contest/454391#problem/Ahttps://www.cnblogs.com/lhm-/p/12229789.html#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;typedef long long ll;...原创 2021-08-20 16:14:15 · 107 阅读 · 0 评论 -
快读模板 ( C++ )
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;typedef long long ll;inline long long read() { long long n=0, sgn=1; char ch=getchar(); while((ch<'0'||ch&原创 2021-08-18 10:33:41 · 416 阅读 · 0 评论