C++类和对象——第三关

news2025/5/21 0:30:58

在阅读此篇文章之前,请先阅读博主之前的文章:

C++类和对象第一关-CSDN博客

C++类和对象——第二关-CSDN博客

以便更好的理解本文章。

目录

运算符重载

(一)运算符重载

(二)赋值类运算符函数的重载:

定义:

赋值运算符重载的特点:

(三)日期类的实现

(四)const成员函数

(五)取地址运算符重载


运算符重载

(一)运算符重载

• 当运算符被⽤于类类型的对象时,C++语⾔允许我们通过运算符重载的形式指定新的含义。C++规定类类型对象使⽤运算符时,必须转换成调⽤对应运算符重载,若没有对应的运算符重载,则会编译报错。


• 运算符重载是具有特殊名字的函数,他的名字是由operator和后⾯要定义的运算符共同构成。和其他函数⼀样,它也具有其返回类型和参数列表以及函数体。

就把他当做普通的函数就好,只不过函数名不一样罢了。

• 重载运算符函数的参数个数和该运算符作⽤的运算对象数量⼀样多。⼀元运算符有⼀个参数,⼆元运算符有两个参数,⼆元运算符的左侧运算对象传给第⼀个参数,右侧运算对象传给第⼆个参数。

• 如果⼀个重载运算符函数是成员函数,则它的第⼀个运算对象默认传给隐式的this指针,因此运算符重载作为成员函数时,参数⽐运算对象少⼀个。

• 运算符重载以后,其优先级和结合性与对应的内置类型运算符保持⼀致。

• 不能通过连接语法中没有的符号来创建新的操作符:⽐如operator@。

• .* :: sizeof ?: . 注意以上5个运算符不能重载。(选择题⾥⾯常考,⼤家要记⼀
下)

• 重载操作符⾄少有⼀个类类型参数,不能通过运算符重载改变内置类型对象的含义,如: intoperator+(int x, int y)

• ⼀个类需要重载哪些运算符,是看哪些运算符重载后有意义,⽐如Date类重载operator-就有意义,但是重载operator+就没有意义。

• 重载++运算符时,有前置++和后置++,运算符重载函数名都是operator++,⽆法很好的区分。C++规定,后置++重载时,增加⼀个int形参,跟前置++构成函数重载,⽅便区分。

• 重载<<和>>时,需要重载为全局函数,因为重载为成员函数,this指针默认抢占了第⼀个形参位置,第⼀个形参位置是左侧运算对象,调⽤时就变成了对象<<cout,不符合使⽤习惯和可读性。重载为全局函数把ostream/istream放到第⼀个形参位置就可以了,第⼆个形参位置

当类类型对象。

(二)赋值类运算符函数的重载:

定义:

赋值运算符重载是⼀个默认成员函数,⽤于完成两个已经存在的对象直接的拷⻉赋值,这⾥要注意跟拷⻉构造区分,拷⻉构造⽤于⼀个对象拷⻉初始化给另⼀个要创建的对象

赋值运算符重载的特点:

1. 赋值运算符重载是⼀个运算符重载,规定必须重载为成员函数。赋值运算重载的参数建议写成const当前类类型引⽤,否则会传值传参会有拷⻉
2. 有返回值,且建议写成当前类类型引⽤,引⽤返回可以提⾼效率,有返回值⽬的是为了⽀持连续赋值场景。
3. 没有显式实现时,编译器会⾃动⽣成⼀个默认赋值运算符重载,默认赋值运算符重载⾏为跟默认拷⻉构造函数类似,对内置类型成员变量会完成值拷⻉/浅拷⻉(⼀个字节⼀个字节的拷⻉),对⾃定义类型成员变量会调⽤他的赋值重载函数。
4. 像Date这样的类成员变量全是内置类型且没有指向什么资源,编译器⾃动⽣成的赋值运算符重载就可以完成需要的拷⻉,所以不需要我们显⽰实现赋值运算符重载。像Stack这样的类,虽然也都是内置类型,但是_a指向了资源,编译器⾃动⽣成的赋值运算符重载完成的值拷⻉/浅拷⻉不符合我们的需求,所以需要我们⾃⼰实现深拷⻉(对指向的资源也进⾏拷⻉)。像MyQueue这样的类型内部主要是⾃定义类型Stack成员,编译器⾃动⽣成的赋值运算符重载会调⽤Stack的赋值运算符重载,也不需要我们显⽰实现MyQueue的赋值运算符重载。这⾥还有⼀个⼩技巧,如果⼀个类显⽰实现了析构并释放资源,那么他就需要显⽰写赋值运算符重载,否则就不需要。

#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>

using namespace std;

// 赋值运算符重载
class Date {
public:
	Date(int day=1,int month=1,int year=2001)
	{
		_day = day;
		_month = month;
		_year = year;
	}

	~Date()
	{}

	// 赋值运算符重载:用于两个已经存在的对象之间的拷贝
	Date& operator=(const Date& d)// 返回引用能够减少拷贝
	{
		// 检查自己拷贝自身的情况,
		if (this != &d)// 检查两者地址是否一致
		{
			// 如果地址不一致
			_day = d._day;
			_month = d._month;
			_year = d._year;
		}
		return *this;// 返回当前被拷贝的对象,这样能够支持连续赋值
	}

	void print()
	{
		cout <<this->_year << " /" << this->_month << " /" << this->_day << endl;
	}

private:
	int _year;
	int _month;
	int _day;
};

void Test()
{
	Date d1(2001,9,18);
	Date d2(2002,9,18);
	Date d3(2003,9,18);
	cout << "未赋值拷贝" << endl;

	d1.print();
	d2.print();
	d3.print();	

	d1 = d2 = d3;
	cout << "赋值拷贝" << endl;
	d1.print();
	d2.print();
	d3.print();
}

int main()
{
	Test();

	return 0;
}

其实这个赋值拷贝除了第一点和拷贝构造不一样,还支持连续赋值拷贝之外其他的都和拷贝构造函数是一样的。

(三)日期类的实现

根据以上运算符重载的所有特性。我们来实现一个日期类来详细看一下。

日期类的声明:Date.h

#pragma once
#pragma once
#include<iostream> 
#include<cassert>

using namespace std;

class Date
{
public:

	// 友元声明
	friend ostream& operator<<(ostream& out, const Date& d);
	friend istream& operator>>(istream& in, Date& d);

	// 获取某年某月的天数

	int GetMonthDay(int year, int month);

	// 全缺省的构造函数

	Date(int year = 1900, int month =#pragma once
#include<iostream> 
#include<assert.h>

using namespace std;

class Date
{
public:

	// 友元声明
	friend ostream& operator<<(ostream& out, const Date& d);
	friend istream& operator>>(istream& in, Date& d);

	// 获取某年某月的天数

	int GetMonthDay(int year, int month);

	// 全缺省的构造函数

	Date(int year = 1900, int month = 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;
	}

	// 拷贝构造函数

  // d2(d1)

	Date(const Date& d)
	{
		_year = d._year;
		_month = d._month;
		_day = d._day;
	}

	// 赋值运算符重载

  // d2 = d3 -> d2.operator=(&d2, d3)
	Date& operator=(const Date& d)
	{
		_year = d._year;
		_month = d._month;
		_day = d._day;
		return *this;
	}

	// 析构函数

	// ~Date();

	// 日期+=天数
	Date& operator+=(int day);


	// 日期+天数
	Date operator+(int day);

	// 日期-天数

	Date operator-(int day);

	// 日期-=天数

	Date& operator-=(int day);

	// 前置++

	Date& operator++();

	// 后置++

	Date operator++(int);

	// 后置--

	Date operator--(int);

	// 前置--

	Date& operator--();

	// >运算符重载

	bool operator>(const Date& d);

	// ==运算符重载

	bool operator==(const Date& d);

	// >=运算符重载

	bool operator >= (const Date& d);

	// <运算符重载

	bool operator < (const Date& d);

	// <=运算符重载

	bool operator <= (const Date& d);

	// !=运算符重载

	bool operator != (const Date& d);

	// 日期-日期 返回天数

	int operator-(const Date& d);

	void Print()
	{
		cout << _year << '/' << _month << '/' << _day << endl;
	}

	// 日期检查
	bool CheckDate()
	{
		if (_year < 0 || _month <= 0 || _month > 12 || _day <= 0 || _day > 31)
		{
			return false;
		}
		
		return true;
	}

private:

	int _year;

	int _month;

	int _day;

};


// 流插入 << 运算符重载
ostream& operator<<(ostream& out, const Date& d);

// 流提取 >> 运算符重载
istream& operator>>(istream& in, Date& d); 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;
	}

	// 拷贝构造函数

  // d2(d1)

	Date(const Date& d)
	{
		_year = d._year;
		_month = d._month;
		_day = d._day;
	}

	// 赋值运算符重载

  // d2 = d3 -> d2.operator=(&d2, d3)
	Date& operator=(const Date& d)
	{
		_year = d._year;
		_month = d._month;
		_day = d._day;
		return *this;
	}

	// 析构函数

	// ~Date();

	// 日期+=天数
	Date& operator+=(int day);


	// 日期+天数
	Date operator+(int day);

	// 日期-天数

	Date operator-(int day);

	// 日期-=天数

	Date& operator-=(int day);

	// 前置++

	Date& operator++();

	// 后置++

	Date operator++(int);

	// 后置--

	Date operator--(int);

	// 前置--

	Date& operator--();

	// >运算符重载

	bool operator>(const Date& d);

	// ==运算符重载

	bool operator==(const Date& d);

	// >=运算符重载

	bool operator >= (const Date& d);

	// <运算符重载

	bool operator < (const Date& d);

	// <=运算符重载

	bool operator <= (const Date& d);

	// !=运算符重载

	bool operator != (const Date& d);

	// 日期-日期 返回天数

	int operator-(const Date& d);

	void Print()
	{
		cout << _year << '/' << _month << '/' << _day << endl;
	}

	// 日期检查
	bool CheckDate()
	{
		if (_year < 0 || _month <= 0 || _month > 12 || _day <= 0 || _day > 31)
		{
			return false;
		}
		
		return true;
	}

private:

	int _year;

	int _month;

	int _day;

};


// 流插入 << 运算符重载
ostream& operator<<(ostream& out, const Date& d);

// 流提取 >> 运算符重载
istream& operator>>(istream& in, Date& d);

看到friend关键字蒙圈的话请移至下一章节

日期类运算符函数重载的逻辑实现:Date.c

#define _CRT_SECURE_NO_WARNINGS 1

#include "Date.h"


// 获取某年某月的天数

int Date::GetMonthDay(int year, int month)
{
	assert(_month > 0 && _month < 13);

	int monthdayarry[] = { -1, 31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31 }; // 31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31

	if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
	{
		return 29;
	}
	else
	{
		return monthdayarry[month];
	}
}

// 日期+=天数
Date& Date::operator+=(int day)
{
	assert(_month > 0 && _month < 13);

	// 日期为负数
	if (day < 0)
	{
		*this -= day;
	}
	// 日期为正数
	_day += day;
	while (_day > GetMonthDay( _year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		++_month;
		if (_month > 12)
		{
			++_year;
			_month = 1;
		}
		// _day -= GetMonthDay(_year, _month);千万记住啊!!算法的步骤不能乱啊,乱了就出问题了。
	}
	return *this;
}


// 日期+天数
Date Date::operator+(int day)
{
	assert(_month > 0 && _month < 13);

	Date tmp = *this;

	tmp += day;
	
	return tmp;
}

// 日期-天数
Date Date::operator-(int day)
{
	assert(_month > 0 && _month < 13);

	Date tmp = *this;

	tmp -= day;

	return tmp;
}

// 日期-=天数
Date& Date::operator-=(int day)
{
	assert(_month > 0 && _month < 13);

	_day -= day;

	while (_day < 0)
	{
		_month--;
		if (_month == 0)
		{
			_year--;
			_month = 12;
		}
		// 因为是当前月减的,要加就要加下一个月的
		_day += GetMonthDay(_year, _month);
	}

	return *this;
}

// 前置++

Date& Date::operator++()
{
	assert(_month > 0 && _month < 13);

	return *this += 1;
}

// 后置++

Date Date::operator++(int)
{
	assert(_month > 0 && _month < 13);

	Date tmp = *this;

	return tmp += 1;
}

// 前置--

Date& Date::operator--()
{
	assert(_month > 0 && _month < 13);

	return *this -= 1;
}

// 后置--

Date Date::operator--(int)
{
	assert(_month > 0 && _month < 13);

	Date tmp = *this;

	return tmp -= 1;
}

// >运算符重载

bool Date::operator>(const Date& d)
{
	assert(_month > 0 && _month < 13);

	if (_year < d._year)
	{
		return false;
	}
	else if (_year == d._year)
	{
		if (_month < d._month)
		{
			return false;
		}
		else if (_month == d._month)
		{
			if (_day < d._day)
			{
				return false;
			}
		}
	}
	return true;
	// 为什么不可以这样写??
	//return _day < d._year
	//	&& _month < d._month
	//	&& _year < d._year;
}

// ==运算符重载

bool Date::operator==(const Date& d)
{
	assert(_month > 0 && _month < 13);

	return _day == d._year
		&& _month == d._month
		&& _year == d._year;
}

// >=运算符重载
bool Date::operator >= (const Date& d)
{
	return *this > d || *this == d;
}

// <运算符重载

bool Date::operator < (const Date& d)
{
	return !(*this >= d);
}

// <=运算符重载

bool Date::operator <= (const Date& d)
{
	return *this < d || *this == d;
}

// !=运算符重载

bool Date::operator != (const Date& d)
{
	return !(*this == d);
}

// 日期-日期 返回天数

int Date::operator-(const Date& d)
{
	assert(_month > 0 && _month < 13);

	int n = 0;
	Date min = *this;
	Date max = d;
	int flag = 1;

	if (*this > d)
	{
		max = *this;
		min = d;
		flag = -1;
	}

	while (min <= max)
	{
		++min;
		++n;
	}

	return n * flag;
}

// 流插入 << 运算符重载
ostream& operator<<(ostream& out, const Date& d)
{
	out << d._year << "/" << d._month << "/" << d._day << endl;

	return out;
}

// 流提取 >> 运算符重载
istream& operator>>(istream& in, Date& d)
{
	do
	{ 
		cout << "请依次输入年月日:>";
		in >> d._year >> d._month >> d._day;
	} while (!d.CheckDate());

	return in;
}

ps:写代码的时候折磨自己很久的一个毛病:传参的实参和形参位置不一样导致出现了bug

测试函数Test.c

#define _CRT_SECURE_NO_WARNINGS 1
#include "Date.h"

// 测试日期+天数和日期 +=天数
void Test01()
{
	Date d1(2001, 6, 18);
	d1.Print();

	Date d2(d1 + 50);

	d2.Print();
}

// 测试-和-=
void  Test02()
{
	Date d1(2001, 6, 18);
	//d1.Print();
	//d1 -= 40;
	//d1.Print();
	Date d2(d1 - 50);

	d2.Print();
}

//  测试++和--
void Test03()
{
	//Date d1(2001, 9, 18);
	//d1.Print();
	//d1++;
	//d1.Print();


	//Date d2(2002, 3, 28);
	//d2.Print();
	//++d2;
	//d2.Print();

	Date d1(2001, 9, 18);
	d1.Print();
	d1--;
	d1.Print();


	Date d2(2002, 3, 28);
	d2.Print();
	--d2;
	d2.Print();
}

// 测试逻辑判断
void Test04()
{
	Date d1(2001, 9, 18);
	Date d2(2002, 3, 28);

	bool judge = (d1 <= d2);
	cout << judge << endl;
}

// 测试日期-日期
void Test05()
{
	Date d1(2001, 9, 28);
	Date d2(2002, 3, 28);

	int day = d1 - d2;

	cout << day << endl;
}

// 测试<< 和 >>
void Test06()
{
	//Date d1(2001, 9, 28);
	//Date d2(2002, 3, 28);
	//cout << d1 << d2;

	Date d1;
	Date d2;
	cin >> d1 >> d2;
	cout << d1 << d2;


}

int main()
{
	//Test01();
	//Test02();
	//Test03();
	//Test04();
	//Test05();
	Test06();
	
	return 0;
}

(四)const成员函数

使用const修饰成员函数,使用const修饰成员函数之后,类的成员变量就不可修改。

如何使用:在成员函数的后面加上一个const就可以了。

#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>

using namespace std;

// 赋值运算符重载
class Date {
public:
	Date(int year = 2001, int month = 1, int day =1)
	{
		_day = day;
		_month = month;
		_year = year;
	}

	~Date()
	{}

	// 赋值运算符重载:用于两个已经存在的对象之间的拷贝
	Date& operator=(const Date& d)// 返回引用能够减少拷贝
	{
		// 检查自己拷贝自身的情况,
		if (this != &d)// 检查两者地址是否一致
		{
			// 如果地址不一致
			_day = d._day;
			_month = d._month;
			_year = d._year;
		}
		return *this;// 返回当前被拷贝的对象,这样能够支持连续赋值
	}

	void print() 
	{
		// 加了const之前不可以修改:this++;
		// 加了const之后不可以修改:this->_year = 2010 并且 不可以修改this指针(this++);
		cout <<this->_year << " /" << this->_month << " /" << this->_day << endl;
	}

private:
	int _year;
	int _month;
	int _day;
};

void Test()
{
	Date d1(2001,9,18);
	Date d2(2002,9,18);
	Date d3(2003,9,18);
	cout << "未赋值拷贝" << endl;

	d1.print();
	d2.print();
	d3.print();	

	d1 = d2 = d3;
	cout << "赋值拷贝" << endl;
	d1.print();
	d2.print();
	d3.print();
}

int main()
{
	Test();

	return 0;
}

原本没加const之前成员函数内部的this指针是这样的:

Date* const this

我们看到类的print成员函数和运算符重载函数,没加const之前:

加了const之后:成员函数里面的this指针变成了这样

const Date* const this

(五)取地址运算符重载

取地址运算符重载分两类:普通取地址运算符重载和const取地址运算符重载。这个运算符成员重载函数也是类的默认函数之一,编译器可以生成,也可以自己写,一般不需要自己写,除非一些特殊的情况。

我们在上述日期类中添加两个&运算符重载函数:

#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>

using namespace std;

// 赋值运算符重载
class Date {
public:
	Date(int year = 2001, int month = 1, int day =1)
	{
		_day = day;
		_month = month;
		_year = year;
	}

	~Date()
	{}

	// 赋值运算符重载:用于两个已经存在的对象之间的拷贝
	Date& operator=(const Date& d) // 返回引用能够减少拷贝
	{
		// 检查自己拷贝自身的情况,
		if (this != &d) // 检查两者地址是否一致
		{
			// 如果地址不一致
			_day = d._day;
			_month = d._month;
			_year = d._year;
		}
		return *this;// 返回当前被拷贝的对象,这样能够支持连续赋值
	}

	void print()
	{
		this->_year = 2010;
		// 加了const之前不可以修改:this++;
		// 加了const之后不可以修改:this->_year = 2010 并且 不可以修改this指针(this++);
		cout <<this->_year << " /" << this->_month << " /" << this->_day << endl;
	}

	Date* operator&()
	{
		return this;
		//return nullptr;
	}	
	
	const Date* operator&() const // const Date* operator&(const Date* const this)
	{
		//return nullptr;
		return this;
	}

private:
	int _year;
	int _month;
	int _day;
};

void Test()
{
	//Date d1(2001,9,18);
	//Date d2(2002,9,18);
	//Date d3(2003,9,18);
	//cout << "未赋值拷贝" << endl;

	//d1.print();
	//d2.print();
	//d3.print();	

	//d1 = d2 = d3;
	//cout << "赋值拷贝" << endl;
	//d1.print();
	//d2.print();
	//d3.print();

	Date d1(2001, 9, 18);

	cout << &d1.operator=(d1) << endl;
}

int main()
{
	Test();

	return 0;
}

我们执行之后,发现这个地址是正常的类对象的地址,他是系统开辟栈帧的时候随分配的。

我们将&运算符重载函数修改成空指针或者其他地址之后:

	const Date* operator&() const // const Date* operator&(const Date* const this)
	{
		return nullptr;
		//return this;
	

	Date* operator&()
	{
		return (Date*)0x001fff48;
		//return this;
	}	

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2214667.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于EBAZ4205矿板的图像处理:16基于小波变换的图像分解及其重建

基于EBAZ4205矿板的图像处理&#xff1a;17基于小波变换的图像分解及其重建 特别说明 这个项目的代码不会开源&#xff0c;因为这个项目的一大部分是在实习的公司做的&#xff0c;所以仅提供思路和展示&#xff0c;展示一下我的能力。 先看效果 这次让小牛和小绿做模特 经过…

C++模板初阶,只需稍微学习;直接起飞;泛型编程

&#x1f913;泛型编程 假设像以前交换两个函数需要&#xff0c;函数写很多个或者要重载很多个&#xff1b;那么有什么办法实现一个通用的函数呢&#xff1f; void Swap(int& x, int& y) {int tmp x;x y;y tmp; } void Swap(double& x, double& y) {doubl…

胤娲科技:AI短视频——创意无界,即梦启航

在这个快节奏的时代&#xff0c;你是否曾梦想过用几秒钟的短视频&#xff0c;捕捉生活中的每一个精彩瞬间&#xff1f;是否曾幻想过&#xff0c;即使没有专业的摄影和剪辑技能&#xff0c;也能创作出令人惊艳的作品&#xff1f; 现在&#xff0c;这一切都不再是遥不可及的梦想。…

微前端学习以及分享

微前端学习以及分享 注&#xff1a;本次分享demo的源码github地址&#xff1a;https://github.com/rondout/micro-frontend 什么是微前端 微前端的概念是由ThoughtWorks在2016年提出的&#xff0c;它借鉴了微服务的架构理念&#xff0c;核心在于将一个庞大的前端应用拆分成多…

从MySQL到OceanBase离线数据迁移的实践

本文作者&#xff1a;玉璁&#xff0c;OceanBase 生态产品技术专家。工作十余年&#xff0c;一直在基础架构与中间件领域从事研发工作。现负责OceanBase离线导数产品工具的研发工作&#xff0c;致力于为 OceanBase 建设一套完善的生态工具体系。 背景介绍 在互联网与云数据库技…

LEAP 瞬移工具场景试点游戏关卡

你是否厌倦了在Unity编辑器中浪费时间浏览大型游戏关卡&#xff1f;不要看得比Leap更远&#xff01;这个功能强大的编辑器脚本允许您只需单击一下即可即时传输到场景中的任何位置。告别繁琐的手动导航&#xff0c;迎接闪电般快速的关卡设计。有了Leap&#xff0c;你就可以专注于…

Gin框架官方文档详解04:HTTP/2 推送,JSON相关

官方文档&#xff1a;https://gin-gonic.com/zh-cn/docs/ 注&#xff1a;强烈建议没用过Gin的读者先阅读第一节&#xff1a;第一个Gin应用。 目录 一、HTTP/2 推送二、JSONP三、PureJSON四、SecureJSON五、总结 一、HTTP/2 推送 首先&#xff0c;以“04HTTP2server推送”为根目…

linux 时区问题

一、修改系统时间和时区 查看当前下系统时间和时区 timedatectl设置系统时区 ​sudo timedatectl set-timezone <时区>​&#xff0c;例如&#xff1a; sudo timedatectl set-timezone Asia/Shanghai执行成功则没有输出。 更推荐使用 tzselect​ ​命令&#xff0c;…

通信工程学习:什么是VHDL超高速集成电路硬件描述语言

VHDL&#xff1a;超高速集成电路硬件描述语言 VHDL&#xff0c;全称为Very-High-Speed Integrated Circuit Hardware Description Language&#xff0c;即超高速集成电路硬件描述语言&#xff0c;是一种用于电路设计的高级语言。以下是关于VHDL的详细介绍&#xff1a; 一、起源…

ThingsBoard规则链节点:Split Array Msg节点详解

引言 拆分数组消息节点简介 用法 含义 应用场景 实际项目运用示例 智能仓储管理系统 智能电网监控系统 车联网平台 结论 引言 ThingsBoard是一个功能强大的物联网平台&#xff0c;它提供了设备管理、数据收集与处理以及实时监控等核心功能。其规则引擎允许用户定义复杂…

时序图分析(IIC通信为例)

一、时序图分析&#xff08;IIC通信为例&#xff09; 时序图-->编程 解析&#xff1a;时序概念&#xff1a;一般指可编程器件的编程方法&#xff0c;在单片机编程时&#xff0c;需要根据被控芯片的时序去写程序&#xff0c;把芯片上的时序用代码来实现&#xff0c;方可实…

数据结构4——栈

1. 栈的概念及结构 栈的概念&#xff1a; 栈是一种特殊的线性表&#xff0c;其只允许在固定的一端进行插入和删除元素操作。进行数据插入和删除操作的一端称为栈顶&#xff0c;另一端称为栈底。栈中的数据元素遵守后进先出LIFO&#xff08;Last In First Out&#xff09;的原则…

<Linux> 线程池

一、线程池 1. 池化技术 池化技术是一种在计算机科学中广泛应用的优化技术&#xff0c;它的核心思想是&#xff1a;预先创建并维护一组资源&#xff08;例如线程、连接、对象&#xff09;&#xff0c;供多个任务共享使用&#xff0c;以减少创建和销毁资源的开销&#xff0c;提…

贪吃蛇游戏(代码篇)

我们并不是为了满足别人的期待而活着。 前言 这是我自己做的第五个小项目---贪吃蛇游戏&#xff08;代码篇&#xff09;。后期我会继续制作其他小项目并开源至博客上。 上一小项目是贪吃蛇游戏&#xff08;必备知识篇&#xff09;&#xff0c;没看过的同学可以去看看&#xf…

使用Java API访问Apache Kafka

简介 Kafka是由Apache软件基金会开发的一个开源流处理平台,Kafka是一个功能强大且灵活的平台。 基本情况 软件名称:Apache Kafka 软件平台:跨平台 软件语言:Scala、Java 开发商:Apache软件基金会 软件授权:Apache License 2.0 最近更新时间:2024年7月23日 核心概念 -…

Ubuntu:用户不在sudoers文件中

1、问题 执行sudo xxx命令时&#xff0c;显示&#xff1a; user 不在sudoers文件中 需要查看系统版本进入恢复模式修复。 2、重启进入恢复模式 查看系统命令&#xff1a;uname -r 可能显示为&#xff1a;6.8.0-45-generic 重启Ubuntu系统&#xff0c;在开机时按ESC进入模…

oracle归档日志爆满问题处理

最近客户单位的oracle数据库出了问题&#xff0c;经常出现无法连接,报错提示 ORA-00257: archiver error, Connect internal only, until freed.&#xff0c;手动清除归档日志后可以恢复访问&#xff0c;但是过不了几天依旧会爆满&#xff0c;每日生成的归档日志很大。经过详细…

内部排序算法小结

练习目标&#xff1a; 1、实现 直接插入排序、冒泡排序、SHELL排序和快速排序&#xff1b; 2、随机生成100组数据&#xff0c;每组数据1000个元素。 注意&#xff1a;计时的单位是CPU的clock而非时间&#xff01;&#xff01;&#xff01; 【后续】 1、加入选择排序&#xff1b…

读书笔记《PPT演讲力》大树模型

作者把PPT演讲比作一棵大树&#xff0c;树的每一部分对应着PPT演讲的一个技巧。 根据这个大树模型&#xff0c;是否有联想到自己过往的演讲经历&#xff1f;演讲是否都达到了大树模型中说的效果&#xff1f;根据这个思维导图&#xff0c;结合自己的经历&#xff0c;试着总结3句…

云计算第四阶段-----CLOUND二周目 04-06

cloud 04 今日目标&#xff1a; 一、Pod 生命周期 图解&#xff1a; [rootmaster ~]# vim web1.yaml --- kind: Pod apiVersion: v1 metadata:name: web1 spec:initContainers: # 定义初始化任务- name: task1 # 如果初始化任务失败&#…