C++ 基础思维导图(一)
目录
1、C++基础
IO流
namespace
引用、const
inline、函数参数
重载
2、类和对象
类举例
3、 内存管理
new/delete
对象内存分布
内存泄漏
4、继承
继承权限
继承中的构造与析构
菱形继承
1、C++基础
IO流
#include <iostream>
#include <iomanip> // 对于setprecision, setw等
#include <string>
#include <fstream> // 对于文件操作using namespace std;
int main()
{int num;cin >> num; // 输入流if (cin.fail()){cerr << "input not right"; // 标准err输出}cout << num << endl; // 标准输出// 二进制文件读写ofstream binfile("test.bin", ofstream::out | ofstream::binary);char in[] = "A";binfile.write(in, 1);binfile.put('B');binfile.close();ifstream ifile("test.bin", ofstream::in | ofstream::binary); // 直接构造也可以ifile.seekg(0, ifile.end); // 跳转到文件末尾int length = ifile.tellg(); // 获取当前字符在文件当中的位置,即文件的字符总数ifile.seekg(0, ifile.beg); // 重新回到文件开头char data[1024];ifile.read(data, length); // 将文件当中的数据全部读取到字符串data当中cout << data << endl;ifile.close(); // 关闭文件ofstream outFile("example.txt"); // 只读,创建 ofstream 对象if (!outFile){std::cerr << "Unable to open file for writing";return 1; // 返回错误代码}outFile << "hello" << endl;outFile << "test" << endl;outFile.close();ifstream input("example.txt"); // 只读if (!input){cerr << "Unable to open file";return 1;}std::string line;while (std::getline(input, line)){std::cout << line << std::endl;}input.close(); // 关闭文件fstream file("example.txt", std::ios::in | std::ios::out | std::ios::app);file << "\nAppending this line to the file." << std::endl;file.seekg(0, std::ios::beg);// 从文件读取数据并输出到控制台std::string line1;while (std::getline(file, line1)){std::cout << line1 << std::endl;}file.close(); // 关闭文件return 0;
}
namespace
#include <iostream>
using namespace std;
namespace A
{int a=1;
} // namespace A
namespace B
{int a=2;namespace C{struct T{int a=4;char c;};int a=3;} // namespace C
}; // namespace B
int main()
{cout<<"A::a "<<A::a<<"; B::a "<<B::a<<"; C::a "<<B::C::a<<endl;B::C::T t1;cout<<t1.a<<endl; using B::C::T;T t2;cout<<t2.a<<endl;bool F=true;cout<<boolalpha<<F<<endl; //noboolalpha 输出1int a=1,b=2,c=3;auto max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);//三目运算(a<b? a : b)= 30;//C中的三目运算符返回的是变量值,不能作为左值使用.而C++则可以在任意地方return 0;
}
引用、const
#include <iostream>
using namespace std;
struct A
{int a;char c;
};
void show(A *p)
{cout << "show func 指针调用前" << endl;cout << p->a << "\t" << p->c << endl;p->a = 20;cout << "show fun 指针修改调用后" << endl;cout << p->a << "\t" << p->c << endl;
}
void show1(A &p)
{cout << "show1 引用调用前" << endl;cout << p.a << "\t" << p.c << endl;p.a = 35;cout << "show1 引用修改调用后" << endl;cout << p.a << "\t" << p.c << endl;
}
void show2(A p)
{ // 临时变量实参的一份拷贝,修改对实参没有影响cout << "show2 传值调用前" << endl;cout << p.a << "\t" << p.c << endl;p.a = 45;cout << "show2 传值修改调用后" << endl;cout << p.a << "\t" << p.c << endl;
}
// 指针所指向的内存空间,不能被修改
int operA(const A *p)
{// p->a=10;return 0;
}
// 指针变量本身不能被修改
int operatorA1(A *const pT)
{pT->a = 10;// pT = NULL; //return 0;
}
// 指针变量和所指的值都不可以改变
int operatorA2(const A *const pT)
{// pT->a = 10;// pT = NULL; //cout << "A!" << endl;return 0;
}
// 数据交换, 值交换无法完成
void myswap(int i, int j)
{int c = 0;c = i;i = j;j = c;
}
// 数据交换, 指针直接对实参修改
void myswap1(int *i, int *j)
{int c = 0;c = *i;*i = *j;*j = c;
}
// 数据交换, 引用交换,引用做函数参数时不用初始化
void myswap2(int &i, int &j)
{int c = 0;c = i;i = j;j = c;
}
// 返回a的本身 a的副本
int getA1()
{int a = 10;return a;
}
/*想让引用返回可以用就需要将变量生命为static的
/*当函数返回值为引用时若返回栈变量不能成为其它引用的初始值
不能作为左值使用若返回静态变量或全局变量可以成为其他引用的初始值
即可作为右值使用,也可作为左值使用*/
int &getA2()
{int a = 20;// warning: reference to local variable ‘a’ returned [-Wreturn-local-addr]return a;
}
int *getA3()
{int a = 30;// warning: reference to local variable ‘a’ returnedreturn &a;
}
int main()
{// const operatorA*const int x = 0;int const y = 2;// x=3; y=2;//两个定义一样的效果,修改报错assignment of read-only variable 'x'// int const z; //未被初始化 error: uninitialized 'const z// 引用int var = 10;int &temp = var; // 引用需要初始化,像一个常量,有自己的空间sizeof与指针一样temp = 12; // 变量的别名cout << "var: " << var << " " << temp << endl; // 修改引用同修改本身 12 12int temp1 = 10, temp2 = 110;cout << "berfor myswap temp1: " << temp1 << " temp2: " << temp2 << endl;myswap(temp1, temp2); // 数据交换, 值交换无法完成cout << "after myswap temp1: " << temp1 << " temp2: " << temp2 << endl;myswap1(&temp1, &temp2); // 指针传入交换cout << "after myswap temp1: " << temp1 << " temp2: " << temp2 << endl;myswap2(temp1, temp2); // 引用的本质时间接修改实参,编译器创造了指针然后修改// 间接赋值的三个条件,1)定义两个变量,2)变量之间建立关联,3)形参间接修改实参;引用是后两个条件合二为一cout << "after myswap temp1: " << temp1 << " temp2: " << temp2 << endl;cout << " ----复杂类型引用 学习---- " << endl;A t = {101, 'A'}; // 结构体 列表初始化cout << "main调用指针调用前" << endl;cout << t.a << "\t" << t.c << endl; // 101 Ashow(&t);cout << "main调用指针调用后" << endl;cout << t.a << "\t" << t.c << endl;show1(t);cout << "main引用调用后" << endl;cout << t.a << "\t" << t.c << endl;show2(t);cout << "main传值调用后" << endl;cout << t.a << "\t" << t.c << endl;cout << "------函数返回值是一个引用-------" << endl;int ga = 1;int ga1 = 2;ga = getA1();// ga1=getA2(); //引用相当于指针,临时变量返回易出错。因为值被释放了// int &ga2=getA2(); //栈变量返回不能作为初始值cout << "ga: " << ga << endl;int *p = NULL; // 指针可以为null// p = getA3();// cout << *p << endl; // 证明了引用和指针一样,返回临时变量的指针,有可能被释放了再去使用出现异常return 0;
}
inline、函数参数
#include <iostream>
using namespace std;
#define MYFUNC(a,b)((a)<(b)?(a):(b))
inline void printA()
{int a = 10;cout << "a:" << a << endl;
}
inline int Myfun(int a,int b){return a<b?a:b;
}
struct A
{char c;int a;
};
void show(const A &m)
{// m.c=10; // error: assignment of member 'A::c' in read-only objectcout << m.a << endl;
}
//函数占位参数 函数调用时,必须写够参数
void func1(int a,int b, int){cout<<"a: "<<a<<" b: "<<b<<endl;
}
//默认参数与占位参数
void func2(int a,int b, int=0){cout<<"a: "<<a<<" b: "<<b<<endl;
}
// void func3(int a=0,int b){ 在默认参数规则 ,如果默认参数出现,那么右边的都必须有默认参数
// }
int main()
{int a = 10;int &b = a; // 普通引用必须初始化// int &c=10; //字面值不可以,引用要取地址int x = 12;const int &y = x; // 让变量引用只读属性不能通过y修改x// y=20; 不能修改, x可以改变x = 13; //修改值y也变了// 常引用的初始化可以用变量或者常量值{const int a = 10;// int &m=11;const int &m = 40;}A t = {'1', 1};show(t);cout<<" ----inline--------"<<endl;printA();//与下相同// {// int a = 10;// cout<<"a"<<a<<endl;// }C++编译器直接将函数体插入在函数调用的地方//内联函数省去了普通函数调用时压栈,跳转和返回的开销int a1=1, b1=3;int c=MYFUNC(a1,b1);int d=Myfun(a1,b1);cout<<" define: a1: "<<a1<<" b1: "<<b1<<" c: "<<c<<endl;cout<<" inlice: a1: "<<a1<<" b1: "<<b1<<" d: "<<d<<endl;//int c1=MYFUNC(++a1,b1); //a=3 b=3 c=3 //==>宏替换并展开 ((++a) < (b) ? (++a) : (b)) //a=3 b=3 c=3// cout<<" define ++: a1: "<<a1<<" b1: "<<b1<<" c1: "<<c1<<endl;int d1=Myfun(++a1,b1); //a=2 b=3 c=2cout<<" inlice ++: a1: "<<a1<<" b1: "<<b1<<" d: "<<d1<<endl;func1(a,b,c); //占位符必须有参数func2(a,b); //okfunc2(a,b,c); //okreturn 0;
}
重载
#include <iostream>
using namespace std;
int func(int x)
{return x;
}
int func(int x, int y)
{return x + y;
}
// 函数重载 和 函数默认参数 在一起
// int func(int x, int y, int c = 0)
// {
// return x + y + c;
// }
auto func(const string &s)
{return s.size();
}
// void func(int x,int y){ //函数返回值不是函数重载的判断标准
// x= x+y;
// cout<<x<<endl;
// }
void func(string *s1, string *s2)
{cout << *s1 << "\t" << *s2 << endl;
}
// 定义一个函数类型
typedef int(myfun)(int a, int b);
myfun *f = nullptr; // 定义函数指针,指向函数入口
// 声明一个函数指针类型
typedef int (*myfunc1)(int a, int b);
//myfunc1 fp = nullptr;
// 定义一个函数指针 变量
void (*myVarPFunc)(int a, int b);
int main()
{int a = 0;a = func(1);cout << "func a: " << a << endl;// a=func(1,2); //重载与默认参数在一起产生了二义性cout << "func1 a: " << a << endl;cout << "func2 a: " << func("abcd") << endl;string s = "abcde";string s1 = "hjic";func(&s, &s1);myfunc1 fp;fp = func;cout<<fp(1,3)<<endl;return 0;
}
2、类和对象
类举例
#include <iostream>
#include <string>class Student {
private:std::string name; // 学生姓名int age; // 学生年龄public:// 默认构造函数Student() : name("Unknown"), age(0) {std::cout << "Default constructor called.\n";}// 带参数的构造函数Student(const std::string& name, int age) : name(name), age(age) {std::cout << "Parameterized constructor called for " << name << ".\n";}// 拷贝构造函数Student(const Student& other) {this->name = other.name; // 使用 this 指针this->age = other.age; // 使用 this 指针std::cout << "Copy constructor called for " << this->name << ".\n";}// 拷贝赋值运算符Student& operator=(const Student& other) {if (this != &other) { // 防止自我赋值this->name = other.name; // 使用 this 指针this->age = other.age; // 使用 this 指针std::cout << "Copy assignment operator called for " << this->name << ".\n";}return *this; // 返回当前对象的引用}// 析构函数~Student() {std::cout << "Destructor called for " << name << ".\n";}// 显示学生信息void display() const {std::cout << "Name: " << name << ", Age: " << age << "\n";}
};int main() {// 使用默认构造函数Student student1;student1.display();// 使用带参数的构造函数Student student2("Alice", 20);student2.display();// 使用拷贝构造函数Student student3 = student2; // 调用拷贝构造函数student3.display();// 使用拷贝赋值运算符Student student4;student4 = student2; // 调用拷贝赋值运算符student4.display();return 0;
}
3、 内存管理
new/delete
#include <iostream>
#include <cstdlib> // 包含 malloc 和 free 的头文件class MyClass {
public:MyClass() {std::cout << "MyClass constructor called.\n";}~MyClass() {std::cout << "MyClass destructor called.\n";}
};
int main() {// 使用 new 和 deletestd::cout << "Using new and delete:\n";MyClass* obj1 = new MyClass(); // 使用 new 分配内存delete obj1; // 使用 delete 释放内存// 使用 malloc 和 freestd::cout << "\nUsing malloc and free:\n";// 注意:malloc 只分配内存,不调用构造函数MyClass* obj2 = (MyClass*)malloc(sizeof(MyClass)); // 使用 malloc 分配内存if (obj2) {new (obj2) MyClass(); // 手动调用构造函数}// 使用 free 释放内存,但需要手动调用析构函数if (obj2) {obj2->~MyClass(); // 手动调用析构函数free(obj2); // 使用 free 释放内存}return 0;
}
对象内存分布
#include <iostream>
#include <string>class MyClass {
public:int value;MyClass(int v) : value(v) {std::cout << "constructor called for value: " << value << "\n"; //10}~MyClass() {std::cout << "destructor called for value: " << value << "\n";}
};// 全局变量,存储在数据区
MyClass globalObj(10); int main() {// 栈区对象MyClass stackObj(20); std::cout << "Address of stackObj: " << &stackObj << "\n"; //10// 堆区对象MyClass* heapObj = new MyClass(30);std::cout << "Address of heapObj: " << heapObj << "\n";// 数据区对象std::cout << "Address of globalObj: " << &globalObj << "\n";// 程序区(代码区)对象std::cout << "Address of main function: " << (void*)main << "\n";// 释放堆区对象delete heapObj;/*constructor called for value: 10constructor called for value: 20Address of stackObj: 0x6963bffbd4constructor called for value: 30Address of heapObj: 0x22296241640Address of globalObj: 0x7ff6cc537030Address of main function: 0x7ff6cc531450destructor called for value: 30destructor called for value: 20destructor called for value: 10*/return 0;
}
内存泄漏
#include <iostream>class MyClass {
public:MyClass() {std::cout << "MyClass constructor called.\n";}~MyClass() {std::cout << "MyClass destructor called.\n";}
};void createMemoryLeak() {MyClass* obj = new MyClass(); // 动态分配内存// 忘记释放内存,导致内存泄漏
}
void createNoMemoryLeak() {std::unique_ptr<MyClass> obj = std::make_unique<MyClass>(); // 使用智能指针// 不需要手动释放内存,智能指针会自动管理
}int main() {for (int i = 0; i < 5; ++i) {createMemoryLeak(); // 每次调用都会造成内存泄漏}std::cout << "Memory leak has occurred.\n";for (int i = 0; i < 5; ++i) {createNoMemoryLeak(); // 不会造成内存泄漏}return 0;
}
4、继承
继承权限
#include <iostream>
using namespace std;// 继承
// public 修饰的成员变量 方法 在类的内部 类的外部都能使用
// protected: 修饰的成员变量方法,在类的内部使用 ,在继承的子类中可用 ;其他 类的外部不能被使用
// private: 修饰的成员变量方法 只能在类的内部使用 不能在类的外部
// 这几个修饰符用在继承里影响的是子类的访问全限// 类型兼容性原则
class Parent
{
public:void show(){cout << " show 父类" << endl;a = 0;b = 1;c = 2;cout << "a: " << a << " b: " << b << " c: " << c << endl;}int a;Parent(){cout << " --父类 无参 构造 --" << endl;}Parent(const Parent &p){cout << " 父类 拷贝 构造--- " << endl;}protected:int b;private:int c;
};
class Child1 : public Parent
{
private:int c1; // 子类有自己的属性
public:int a1;void show1(){ // 访问控制a1 = 1;b1 = 2;c1 = 3;cout << " show child1 子类1" << endl;cout << a << b << a1 << b1 << c1 << endl;//<< c 在子类范围内父类里的属性不变,c是私有已经是类外了}protected:int b1;
};
class Child2 : protected Parent
{
public:int a2;void show2(){ // 访问控制 protected继承,public变成protected,a2 = 2;b2 = 4;c2 = 4;cout << " child2 子类2" << endl;cout << a << b << a2 << b2 << c2 << endl;//<< c 在子类范围内父类里的属性不变,c是私有已经是类外了}protected:int b2;private:int c2; // 子类有自己的属性
public:
};
class Child3 : private Parent
{
public:int a3;void show3(){ // 访问控制 私有继承,全变私有,a = 0;b = 1;a3 = 4;b3 = 4;c3 = 5;cout << " child3 子类3" << endl;cout << a << b << a3 << b3 << c3 << endl;//<< c 在子类范围内父类里的属性不变,c是私有已经是类外了}protected:int b3;private:int c3;
};
void howShow(Parent *base){ //指针base->show();//父类成员函数
}
void howShow1(Parent &base){ //引用base.show();//父类成员函数
}int main()
{Child1 cl;// 子类继承了父类的所有属性和方法cout << " 公有继承 " << endl;cl.a = 1; // public ,类外可以// 全是类外不可以访问// cl.b=1;// cl.c=1;// cl.a1=2;// cl.b1=2;// cl.c1=3;cl.show1();cout << " 保护共有继承 " << endl;Child2 c2;// 子类继承了父类的所有属性和方法// c2.a = 1; //变protected ,类外可以// 全是类外不可以访问// c2.b=1;// c2.c=1;// c2.a2=2;// c2.b2=2;// c2.c2=3;c2.show2();Child3 c3;// 私有更不用说了c3.show3();Parent p1;p1.show();//基类指针指向子类Parent *p=nullptr;p=&cl;p->show();//指针做函数参数howShow(p);howShow(&cl);//引用做函数参数howShow1(p1);howShow1(cl);//第二层含义//可以让子类对象 初始化 父类对象//子类就是一种特殊的父类Parent p3 = cl;return 0;
}
继承中的构造与析构
#include <iostream>
#include <cstring>
using namespace std;/*1、子类对象在创建时会首先调用父类的构造函数2、父类构造函数执行结束后,执行子类的构造函数3、当父类的构造函数有参数时,需要在子类的初始化列表中显示调用4、析构函数调用的先后顺序与构造函数相反
*/
class Object
{
public:Object(int a, int b){this->a = a;this->b = b;cout<<"object构造函数 执行 "<<"a"<<a<<" b "<<b<<endl;}~Object(){cout<<"object析构函数 \n";}
protected:int a;int b;
};
class Parent : public Object
{
public:Parent(int p) : Object(1, 2){this->p = p;cout<<"父类构造函数..."<<p<<endl;}~Parent(){cout<<"析构函数..."<<p<<endl;}void printP(int a, int b){cout<<"我是爹..."<<endl;}
protected:int p;};
class child : public Parent
{
public:child(int p) : Parent(p) , obj1(3, 4), obj2(5, 6){this->p = p;cout<<"子类的构造函数"<<p<<endl;}~child(){cout<<"子类的析构"<<p<<endl;}void printC(){cout<<"我是儿子"<<endl;}
protected:int p;Object obj1;Object obj2;
};
菱形继承
#include <iostream>// 基类
class Base {
public:void show() {std::cout << "Base class show function called.\n";}
};// 派生类 A
class DerivedA : public Base {
public:void show() {std::cout << "DerivedA class show function called.\n";}
};// 派生类 B
class DerivedB : public Base {
public:void show() {std::cout << "DerivedB class show function called.\n";}
};// 最终派生类 C
class DerivedC : public DerivedA, public DerivedB {
public:void show() {std::cout << "DerivedC class show function called.\n";}
};int main() {DerivedC obj;// 调用 DerivedC 的 show 方法obj.show(); // 输出 DerivedC 的 show 方法// 访问基类的 show 方法obj.DerivedA::show(); // 明确调用 DerivedA 的 show 方法obj.DerivedB::show(); // 明确调用 DerivedB 的 show 方法return 0;
}
在菱形继承中,DerivedC 通过 DerivedA 和 DerivedB 都继承了 Base 类的成员。如果不明确指定,编译器无法确定应该调用 DerivedA 还是 DerivedB 中的 Base 类成员,这就导致了二义性。
如果加virtual就可以访问基类的 show 方法 obj.Base::show(); // 通过虚继承,只有一个 Base 的实例 。
相关文章:

C++ 基础思维导图(一)
目录 1、C基础 IO流 namespace 引用、const inline、函数参数 重载 2、类和对象 类举例 3、 内存管理 new/delete 对象内存分布 内存泄漏 4、继承 继承权限 继承中的构造与析构 菱形继承 1、C基础 IO流 #include <iostream> #include <iomanip> //…...

【gopher的java学习笔记】依赖管理方式对比(go mod maven)
什么是go mod go mod是Go语言官方引入的模块管理工具,旨在简化项目依赖管理,提高构建的可重复性和稳定性。以下是关于go mod的详细介绍: 在go mod之前,Go语言主要依赖GOPATH和vendor目录来管理项目依赖。然而,这种方式…...

CTFshow—远程命令执行
29-35 Web29 代码利用正则匹配过滤了flag,后面加了/i所以不区分大小写。 可以利用通配符绕过 匹配任何字符串/文本,包括空字符串;*代表任意字符(0个或多个) ls file * ? 匹配任何一个字符(不…...

Qt之简易音视频播放器设计(十五)
Qt开发 系列文章 - MediaPlayer(十五) 目录 前言 一、QMediaPlayer 二、实现方式 1.添加multimedia 2.创建类vedioplayer 3.UI设计 4.用户使用 5.效果演示 总结 前言 利用Qt进行音视频播放器设计,首先比较方便使用的是Qt自带的音视…...

ArrayList 和LinkedList的区别比较
前言 ArrayList和LinkedList的主要区别在于它们的底层数据结构、性能特点以及适用场景。ArrayList和LinkedList从名字分析,他们一个是Array(动态数组)的数据结构,一个是Linked(链表)的数据结构&#x…...

Wallpaper壁纸制作学习记录13
骨骼物理模拟 Wallpaper Engine还允许您为人偶变形骨骼配置某些物理模拟。选择骨骼时,点击编辑约束来配置骨骼这些属性。 警告 请记住,物理模拟可能会根据用户的最大FPS设置略微改变其行为。 Wallpaper Engine编辑器将始终以高帧速率渲染。您可以将壁纸…...

Visual Studio 2022安装教程
1、下载网址 Visual Studio 2022 IDE安装网址借助 Visual Studio 设计,具有自动完成、构建、调试、测试功能的代码将与 Git 管理和云部署融为一体。https://visualstudio.microsoft.com/zh-hans/vs/ 点击图片所示 双击运行 2、安装 点击C桌面开发(右边…...

std__invoke 的使用
std__invoke 的使用 文章目录 std__invoke 的使用1. std::invoke 的功能2. 语法3. 使用场景1. 调用普通函数2. 调用成员函数3. 调用成员函数(通过指针或引用)4. 调用函数对象(仿函数)5. 调用 Lambda 表达式 4. std::invoke 的优势…...

2501d,d.109
原文 2.109.0带来了15个主要更改和26个修复的Bugzilla问题.非常感谢39位贡献者,是他们使2.109.0变成可能. 更改编译器 1,[下一版]现在,为类型实例的成员设置别名是个错误 2,添加位字段内省功能 3,添加了从CTFE写入消息的__ctfeWrite 4,现在-verrors也限制弃用警告 5,dtoh为e…...

1、蓝牙打印机环境搭建
本项目采用stm32f103c8T6芯片,通过库函数实现打印功能,并配置有小程序蓝牙通信上位机。 1、创建文件夹目录 core文件夹存放核心库文件 LIB文件夹存放标准库函数文件 这里可以删减,用不到的可以不要。 obj存放编译后的文件 project存放项目…...

Axure RP11安装学习
安装: 官网下载地址:Axure RP - UX Prototypes, Specifications, and Diagrams in One Tool 设置自己的安装目录,一步步安装即可。 汉化: 汉化包下载地址: 链接: https://pan.baidu.com/s/1eIRoGkVqAY3u3I27lgDJ6A…...

axios和fetch的实现原理以及区别,与XMLHttpRequest的关系,并结合react封装统一请求示例
Axios 和 Fetch 对比及统一请求封装 1. Axios 基础用法 1.1 安装和引入 // 安装 npm install axios// 引入 import axios from axios;1.2 基本请求方法 // GET 请求 axios.get(/api/users).then(response > console.log(response.data)).catch(error > console.error…...

矩阵运算提速——玩转opencv::Mat
介绍:用Eigen或opencv::Mat进行矩阵的运算,比用cpp的vector或vector进行矩阵运算要快吗? 使用 Eigen 或 OpenCV 的 cv::Mat 进行矩阵运算通常比使用 std::vector<int> 或 std::vector<double> 更快。这主要有以下几个原因: 优化的底层实现…...

C++软件设计模式之模板方法模式
模板方法模式是面向对象软件设计模式之一,其主要意图是在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中实现。模板方法使得子类可以在不改变算法结构的情况下重新定义算法的某些特定步骤。 动机 在软件开发中,常常会遇到这样的情…...
神经网络的初始化方式都有哪些?
一、概念 神经网络的初始化是深度学习中的一个关键步骤,它指的是在训练开始前为神经网络的权重和偏置设置初始值。合适的初始化方法可以加速模型的收敛,提高训练效果,甚至影响模型的最终性能。当然,目前我们使用Torch、TensorFlow…...

const成员函数
在c中经常看到这样的声明: class A{ ... int fun1() const; //const成员函数 int fun2() const; //const成员函数private: int a; //属于状态 static int b; //不属于状态,属于类 } 这个const关键字声明了这个函数是const成员函数,con…...

物理知识1——电流
说起电流,应该从电荷说起,而说起电荷,应该从原子说起。 1 原子及其结构 常见的物质是由分子构成的,而分子又是由原子构成的,有的分子是由多个原子构成,有的分子只由一个原子构成。而原子的构成如图1所示。…...

车载通信架构 --- 智能汽车通信前沿技术
我是穿拖鞋的汉子,魔都中坚持长期主义的汽车电子工程师。 老规矩,分享一段喜欢的文字,避免自己成为高知识低文化的工程师: 所谓鸡汤,要么蛊惑你认命,要么怂恿你拼命,但都是回避问题的根源,以现象替代逻辑,以情绪代替思考,把消极接受现实的懦弱,伪装成乐观面对不幸的…...

Flutter中添加全局防护水印的实现
随着版权意识的加强,越来越多的应用开始在应用内部增加各种各样的水印信息,防止核心信息泄露,便于朔源。 效果如下: 在Flutter中增加全局水印的方式,目前有两种实现。 方案一,在native层添加一个遮罩层&a…...

BGP(Border Gateway Protocol)路由收集器
全球 BGP(边界网关协议)路由收集器的分布情况以及相关数据。以下是主要的信息解读: 地图标记: 每个绿色点代表一个路由收集器的位置。路由收集器分布在全球不同的地区,覆盖了五大区域: ARIN(美…...

【DAGMM】直接跑tip
1.from sklearn.externals import joblib 版本高 joblib没有 直接pip install joblib,然后 import joblib 2.AttributeError: module ‘tensorflow’ has no attribute ‘set_random_seed’ # tf.set_random_seed(args.seed)#tf<2.0 tf.random.set_seed(args.s…...

vscode中调用deepseek实现AI辅助编程
来自 Python大数据分析 费弗里 1 简介 大家好我是费老师,最近国产大模型Deepseek v3新版本凭借其优秀的模型推理能力,讨论度非常之高🔥,且其官网提供的相关大模型API接口服务价格一直走的“价格屠夫”路线,性价比很高…...

AI大模型语音识别转文字
提取音频 本项目作用在于将常见的会议录音文件、各种语种音频文件进行转录成相应的文字,也可从特定视频中提取对应音频进行转录成文字保存在本地。最原始的从所给网址下载对应视频和音频进行处理。下载ffmpeg(https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-…...

可由 (5V) 单片机直接驱动的模块
可由 (5V) 单片机 直接驱动的模块 1. 传感器类 元器件描述温度传感器DS18B20(数字温度传感器)光强传感器光敏电阻(通过 ADC 读取)红外传感器红外接收模块(如 VS1838)超声波传感器HC…...

vue使用树形结构展示文件和文件夹
1. 树形结构显示 显示文件夹和文件:使用 el-tree 组件展示树形结构,文件夹和文件的图标通过 el-icon 进行动态显示。文件夹使用 Folder 图标,文件使用 Files 图标。节点点击:点击树形节点后,会将选中的节点保存到 sel…...

PHP框架+gatewayworker实现在线1对1聊天--聊天界面布局+创建websocket连接(5)
文章目录 聊天界面布局html代码 创建websocket连接为什么要绑定? 聊天界面布局 在View/Index目录下创建index.html html代码 <div id"chat"><div id"nbar"><div class"pull-left">与牛德胜正在聊天...</div…...

LinuxUbuntu打开VSCode白屏解决方案
解决方法是 以root权限打开VSCode sudo /usr/share/code/code --no-sandbox --unity-launch...

在 ESP 上运行 AWTK
AWTK 基于 esp 的移植。 测试硬件平台为 ESP32-S3-Touch-LCD-4.3,其它平台请根据实际平台自行调整。 安装下载工具 建议下载离线版本 ESP IDF v5.3.2 下载代码 git clone https://github.com/zlgopen/awtk-esp.git cd awtk-esp git clone https://github.com/zlg…...

硬件工程师面试题 21-30
把常见的硬件面试题进行总结,方便及时巩固复习。其中包括网络上的资源、大佬们的大厂面试题,其中可能会题目类似,加强印象即可。 更多硬件面试题:硬件工程师面试题 1-10硬件工程师面试题 11-20 21、单片机最小系统需要什么&#x…...

开源架构的容器化部署优化版
上三篇文章推荐: 开源架构的微服务架构实践优化版(New) 开源架构中的数据库选择优化版(New) 开源架构学习指南:文档与资源的智慧锦囊(New) 我管理的社区推荐:【青云交社区…...