C++第五弹 -- 类与对象(中下) (赋值运算符重载函数 const成员函数 取地址操作符重载函数)

news2024/9/21 22:46:56

目录

  • 前言
  • 一. 赋值运算符重载
    • 1. 运算符重载
    • 2. 赋值运算符的重载
    • 3. 前置++ 和 后置++ 重载
  • 二. 日期类的实现
  • 三. const成员函数
  • 四. 取地址及const取地址操作符重载
  • 总结

前言

本文将深入探讨C++中的运算符重载,重点讲解赋值运算符、前置/后置++运算符、取地址运算符的重载方法,以及const成员函数的定义和使用方法。通过日期类的实现示例,展示运算符重载和const成员函数在实际应用中的具体代码实现,帮助读者更好地理解和运用这些C++特性。

博客主页: 酷酷学!!!

感谢关注~


正文开始

一. 赋值运算符重载

1. 运算符重载

C++为了增强代码的可读性引入了运算符重载,运算符重载是具有特殊函数名的函数,也具有其返回值类型,函数名字以及参数列表,其返回值类型与参数列表与普通的函数类似。

函数名字为:关键字operator后面接需要重载的运算符符号。
函数原型:返回值类型 operator操作符(参数列表)

注意:

  • 不能通过连接其他符号来创建新的操作符:比如operator@
  • 重载操作符必须有一个类类型参数
  • 用于内置类型的运算符,其含义不能改变,例如:内置的整型+,不能改变其含义(这样只是更加规范)
  • 作为类成员函数重载时,其形参看起来比操作数数目少1,因为成员函数的第一个参数为隐藏的this
  • .* :: sizeof ?: . 注意以上5个运算符不能重载。这个经常在笔试选择题中出
    现。 (. *运算符表示对象成员解引用操作,一般用作成员函数指针 )

例如:成员函数需要加&才能取到函数指针, 而普通函数函数名就是函数首地址

class OB
{
public:
	void func() 
	{
		cout << "void func()" << endl;
	}
};

typedef void(OB::*PtrFunc)() ;//成员函数指针类型

//int main()
//{
//	// 函数指针
//	// void (*ptr)();
//
//	// 成员函数要加&才能取到函数指针
//	PtrFunc fp = &OB::func;//定义成员函数指针p指向函数func
//
//	OB temp;//定义ob类对象temp
//
//	(temp.*fp)();
//	
//
//	return 0;
//}

在这里插入图片描述

全局的运算符重载operator==


 重载成全局,无法访问私有成员
 1、提供这些成员get和set
 2、友元  后面会讲
 3、重载为成员函数(一般使用这种)
class Date
{
public:
	Date(int year = 1900, int month = 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;
	}
	//private:
	int _year;
	int _month;
	int _day;
};

bool operator==(const Date& d1, const Date& d2)
{
	return d1._year == d2._year
		&& d1._month == d2._month
		&& d1._day == d2._day;
}
void Test()
{
	Date d1(2018, 9, 26);
	Date d2(2018, 9, 27);
	cout << (d1 == d2) << endl;
}

int main()
{
	Date d3(2024, 4, 14);
	Date d4(2024, 4, 15);

	// 显式调用
	operator==(d3, d4);

   // 直接写,装换调用,编译会转换成operator==(d3, d4);
	d3 == d4;//一般习惯上会用这种

	return 0;
}

这里会发现运算符重载成全局的就需要成员变量是公有的, 那么就违背了类的封装性, 这里其实我们可以使用友元, get/set函数, 但是最用的还是将它重载成成员函数

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

	// bool operator==(Date* const this, const Date& d2)
	// 这里需要注意的是,左操作数是this,指向调用函数的对象
	bool operator==(const Date & d2)//const修饰d2的内容d2,其内容不可被修改, 传引用用于提高效率)
	{
		return _year == d2._year;
		&& _month == d2._month
			&& _day == d2._day;
	}
private:
	int _year;
	int _month;
	int _day;
};

int main()
{
	Date d3(2024, 4, 14);
	Date d4(2024, 4, 15);

	// 显式调用
	d3.operator==(d4);

	// 转换调用 等价于d3.operator==(d4);
	d3 == d4;

	int i = 0, j = 1;
	bool ret = i == j;

	return 0;
}

将它重载成成员函数时需要注意, 这里这里第一个参数为隐藏的this指针, 所以实际上我们只需要写一个参数位置就可以了.

2. 赋值运算符的重载

  1. 赋值运算符重载格式
  • 参数类型:const T&,传递引用可以提高传参效率
  • 返回值类型:T&,返回引用可以提高返回的效率,有返回值目的是为了支持连续赋值
  • 检测是否自己给自己赋值
  • 返回*this :要复合连续赋值的含义

代码如下:

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

	Date(const Date& d)
	{
		cout << "Date(const Date& d)" << endl;

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

	// d1 = d4;
	// d1 = d2 = d4;
	// d1 = d1
	// Date operator=(const Date& d)
	/*Date& operator=(const Date& d)
	//我们可以看到这里我们需要将赋值后的对象进行返回才能进行连续赋值,那么是传引用还是传值呢?看下面分析
	{
		if (this != &d)
		{
			_year = d._year;
			_month = d._month;
			_day = d._day;
		}

		return *this;
	}*/

	void Print()
	{
		cout << _year << "-" << _month << "-" << _day << endl;
	}

	~Date()
	{
		cout << "~Date()" << endl;
		_year = -1;
		_month = -1;
		_day = -1;
	}

左: 如下面这两个函数, Date出了作用域就被销毁了 只能传值返回, 返回的是d的一份临时拷贝
右: 如果传引用返回,但是d已经被销毁了, 所以ref是一个随机值

在这里插入图片描述
传引用返回可以减少拷贝次数, 提高程序运行效率

在这里插入图片描述
在这里插入图片描述
这里Date在main函数中, 显然生命周期是整个程序, 所以传引用返回提高效率

  1. 赋值运算符只能重载成类的成员函数不能重载成全局函数
class Date
{
public:
	Date(int year = 1900, int month = 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;
	}
	int _year;
	int _month;
	int _day;
};
// 赋值运算符重载成全局函数,注意重载成全局函数时没有this指针了,需要给两个参数
Date& operator=(Date& left, const Date& right)
{
	if (&left != &right)
	{
		left._year = right._year;
		left._month = right._month;
		left._day = right._day;
	}
	return left;
}
// 编译失败:
// error C2801: “operator =”必须是非静态成员

原因如下:
赋值运算符如果不显示实现, 编译器会生成一个默认的, 此时用户再在类外实现一个全局的赋值运算符重载, 就和编译器在类中生成的默认赋值运算符重载冲突了, 故赋值运算符重载只能是类中的成员函数.

在这里插入图片描述

  1. 用户没有显式实现时,编译器会生成一个默认赋值运算符重载,以值的方式逐字节拷贝。注
    意:内置类型成员变量是直接赋值的,而自定义类型成员变量需要调用对应类的赋值运算符
    重载完成赋值。

跟拷贝构造类似, Date或者MyQueue默认生成的赋值就够用了, 但是类似Stack/List等都需要我们自己实现赋值重载

3. 前置++ 和 后置++ 重载

class Date
{
public:
	Date(int year = 1900, int month = 1, int day = 1)
	{
		_year = year;
		_month = month;
		_day = day;
	}
	// 前置++:返回+1之后的结果
	// 注意:this指向的对象函数结束后不会销毁,故以引用方式返回提高效率
	Date& operator++()
	{
		_day += 1;
		return *this;
	}
	// 后置++:
	// 前置++和后置++都是一元运算符,为了让前置++与后置++形成能正确重载
	// C++规定:后置++重载时多增加一个int类型的参数,但调用函数时该参数不用传递,编译器自动传递
		// 注意:后置++是先使用后+1,因此需要返回+1之前的旧值,故需在实现时需要先将this保存一份,然后给this + 1
		//       而temp是临时对象,因此只能以值的方式返回,不能返回引用
		Date operator++(int)
	{
		Date temp(*this);
		_day += 1;
		return temp;
	}
private:
	int _year;
	int _month;
	int _day;
};
int main()
{
	Date d;
	Date d1(2022, 1, 13);
	d = d1++;    // d: 2022,1,13   d1:2022,1,14
	d = ++d1;    // d: 2022,1,15   d1:2022,1,15
	return 0;
}

二. 日期类的实现

  • Date.h
#pragma once

#include<iostream>
#include<assert.h>
using namespace std;

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

public:
	//声明
	//构造函数需要写(析构函数,拷贝构造函数不需要写)
	Date(int year = 1900, int month = 1, int day = 1);
	void Print();

	//因为要重复使用,所以定义在类中,相当于内联函数
	//获取某年某月有多少天
	int GetMonthDay(int year, int month)
	{
		assert(month > 0 && month < 13);
		static int Month[13] = { -1,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 Month[month];
		}
	}

	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);

	Date& operator+=(int day);
	Date operator+(int day);
	Date& operator-=(int day);
	Date operator-(int day);
	Date& operator=(const Date& d);
	Date& operator++();//前置++
	//返回+1之后的结果
	//注意:this指向的对象函数结束后不会被销毁,故以引用的方式返回提高效率

	Date operator++(int);//后置++
	//前置++和后置++都是一元运算符, 为了让前置++与后置++形参正确重载
	//C++规定:后置++重载时多增加一个int类型的参数, 但调用函数时该参数不用
	//传递,编译器自动传递
	//注意:后置++是先使用后+1,因此需要返回+1之后的旧值, 故需要在实现时
	//先将this保存一份,然后再给this+1,而tmp是临时对象,因此只能以值的方式
	//返回,不能返回引用
	bool CheckDate();
	Date& operator--();
	Date operator--(int);

	//d1 - d2
	int operator-(const Date& d);

	//满足连续调用的条件d1<<d2<<d3,故需要返回值,不会析构,引用返回
	ostream& operator<<(ostream& out);
private:
	int _year;
	int _month;
	int _day;
};

//ostream& operator<<(ostream& out, const Date& d);

内联函数和static修饰的成员函数不具备外部链接属性,没有函数名修饰, 只能在内部使用, 而普通函数在.h文件中写之后, 会被展开到, test.cpp和Date.cpp会重复定义, 导致报错

  • Date.cpp

这里计算两个日期相加比较难算, 可以对比数的进位
在这里插入图片描述

#include"Date.h"

bool Date::CheckDate()
{
	if (_month < 1 || _month>12 || _day<1
		|| _day > GetMonthDay(_year, _month))
		return false;
	else return true;
}

Date::Date(int year, int month, int day)
{
	_year = year;
	_month = month;
	_day = day;

	if (!CheckDate())
	{
		cout << "日期非法" << endl;
	}
}

void Date::Print()
{
	cout << _year << "-" << _month << "-" << _day << endl;
}

bool Date::operator<(const Date& d)
{
	if (_year < d._year)
	{
		return true;
	}
	else if (_year == d._year)
	{
		if (_month < d._month)
		{
			return true;
		}
		else if (_month == d._month)
		{
			return _day < d._day;
		}
	}
	return false;
}

bool Date::operator==(const Date& d)
{
	return _year == d._year
		&& _month == d._month
		&& _day == d._day;
}
//直接进行复用
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);
}

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

Date& Date::operator+=(int day)
{
	//进位实现
	_day += day;
	while (_day > GetMonthDay(_year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		_month++;
		if (_month == 13)
		{
			++_year;
			_month = 1;
		}
	}

	return *this;
}

Date Date::operator+(int day)
{
	Date tmp = *this;
	tmp += day;
	return tmp;
}

Date& Date::operator-=(int day)
{
	//比对加法实现
	_day -= day;
	while (_day < 1)
	{
		_month--;
		if (_month == 0)
		{
			--_year;
			_month = 12;
		}
		_day += GetMonthDay(_year, _month);
	}
	return *this;
}

Date Date::operator-(int day)
{
	Date tmp = *this;
	tmp -= day;
	return tmp;
}

Date& Date::operator=(const Date& d)
{
	if (this != &d)//自己给自己赋值无意义
	{
		_year = d._year;
		_month = d._month;
		_day = d._day;
	}

	return *this;//将自己返回
}

//++d1
Date& Date::operator++()
{
	*this += 1;
	return *this;
}

//d1++
Date Date::operator++(int)
{
	Date tmp = *this;
	tmp += 1;
	return tmp;
}

Date& Date::operator--()
{
	*this -= 1;
	return *this;
}

Date Date::operator--(int)
{
	Date tmp = *this;
	tmp -= 1;
	return tmp;
}

int Date::operator-(const Date& d)
{
	Date max = *this;
	Date min = d;
	int flag = 1;
	if (*this < d)
	{
		max = d;
		min = *this;
		flag = -1;
	}

	int n = 0;
	while (min != max)
	{
		++min;
		++n;
	}
	return n * flag;
}

//d1<<d2<<d3
//ostream& Date::operator<<(ostream& out)
//{
//	out << _year << "年" << _month << "月" << _day << "日" << endl;
//	return out;
//}

ostream& operator<<(ostream& out, const Date& d)
{
	out << d._year << "年" << d._month << "月" << d._day << "日" << endl;
	return out;
}//但是这样写无法访问成员, 怎么办? 友元 或者 将成员置为public
//返回out的引用是将多个输出连接在一起,形成链式调用

istream& operator>>(istream& in, Date& d)
{
	in >> d._year >> d._month >> d._day;
	if (!d.CheckDate())
	{
		cout << "日期非法" << endl;
	}
	return in;
}

在这里插入图片描述

  • test.cpp
#include"Date.h"

int main()
{
	Date d1;
	Date d2(2024, 7, 11);

	int ret = d1 == d2;
	int ret1 = d1 < d2;
	int ret2 = d1 <= d2;

	cout << ret << ret1 << ret2 << endl;

	cout << d1;//这样写会报错,因为参数顺序不匹配
	d1 << cout;//为了解决这个问题,将cout重载写在类外

	return 0;
}

在这里插入图片描述

三. const成员函数

将const修饰的“成员函数”称之为const成员函数,const修饰类成员函数,实际修饰该成员函数
隐含的this指针,表明在该成员函数中不能对类的任何成员进行修改。

但是成员函数中, this指针变量已经被隐藏了, 怎么实现呢?

void Print() const //在函数旁边写const

注意 这里修饰的是this里面所指向的内容, 而编译器的this指针是修饰this指针本身

const Date* this 修饰内容
Date* const this 修饰this
而此处相当于双const
const Date* const this
在这里插入图片描述

如果对象是常量对象,则会调用带有const关键字的Print函数;
如果对象是非常量对象,则会调用不带const关键字的Print函数。
这种行为被称为"常量重载"。

class Date
{
public:
	Date(int year, int month, int day)
	{
		_year = year;
		_month = month;
		_day = day;
	}
	/*void Print()//Date* const this
	{
		cout << "Print()" << endl;
		cout << "year:" << _year << endl;
		cout << "month:" << _month << endl;
		cout << "day:" << _day << endl << endl;
	}*/
	void Print() const //const Date* const this
	{
		cout << "Print()const" << endl;
		cout << "year:" << _year << endl;
		cout << "month:" << _month << endl;
		cout << "day:" << _day << endl << endl;
	}
private:
	int _year; // 年
	int _month; // 月
	int _day; // 日
};
void Test()
{
	const Date d1(2022, 1, 13);//常量对象
	d1.Print();//调用没有const修饰的print涉及权限放大,报错, 调用有const修饰的print可以
	
	Date d2(2022, 1, 13);//非常量对象
	d2.Print();//调用没有const修饰的成员函数权限平移,可以,调用有const修饰的权限缩小,可以
}

四. 取地址及const取地址操作符重载

这两个默认成员函数一般不用重新定义 ,编译器默认会生成。

class Date
{
public:
	Date* operator&()
	{
		return this;
	}

	const Date* operator&()const
	{
		return this;
	}
private:
	int _year; // 年
	int _month; // 月
	int _day; // 日
};

这两个运算符一般不需要重载,使用编译器生成的默认取地址的重载即可,只有特殊情况,才需
要重载,比如想让别人获取到指定的内容!

class A
{
public:
	// 我们不实现,编译器会自己实现,我们实现了编译器就不会自己实现了
	// 一般不需要我们自己实现
	// 除非不想让别人取到这个类型对象的真实地址
	A* operator&()
	{
		cout << "A* operator&()" << endl;

		return nullptr;
	}

	const A* operator&() const
	{
		cout << "const A* operator&() const" << endl;

		return (const A*)0xffffffff;
	}
private:
	int _a1 = 1;
	int _a2 = 2;
	int _a3 = 3;
};

int main()
{
	A aa1;
	const A aa2;

	cout << &aa1 << endl;
	cout << &aa2 << endl;

	return 0;
}

总结

C++中的运算符重载可以增强代码可读性,提高代码效率。
赋值运算符重载只能是类成员函数,不能是全局函数。
前置/后置++运算符重载需要分别定义两个函数,前置++返回引用,后置++返回对象拷贝。
取地址运算符一般不需要重载,使用编译器生成的默认重载即可。
const成员函数修饰的是this指针,表示该函数不能修改类的成员变量。
const成员函数可以被常量对象调用,也可以被非常量对象调用。


完, 如有其他问题, 感谢各位楷模指出

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

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

相关文章

2024 ACT汽车软件与安全技术周 | 龙智携全方位汽车软件开发解决方案亮相,助力应对汽车软件开发功能安全、合规等挑战

2024年7月18-19日&#xff08;周四-周五&#xff09;&#xff0c;2024第三届ACT汽车软件与安全技术周将在上海佘山翰悦阁酒店举办。 龙智即将携汽车开发及管理解决方案创新亮相&#xff0c;并在汽车信息安全技术峰会主会场上发表主题演讲&#xff0c;分享推动汽车软件开发与功…

RAG实践:ES混合搜索BM25+kNN(cosine)

1 缘起 最近在研究与应用混合搜索&#xff0c; 存储介质为ES&#xff0c;ES作为大佬牌数据库&#xff0c; 非常友好地支持关键词检索和向量检索&#xff0c; 当然&#xff0c;支持混合检索&#xff08;关键词检索向量检索&#xff09;&#xff0c; 是提升LLM响应质量RAG(Retri…

【JS|第21期】JavaScript模块化:深入解析三种文件暴露方式

日期:2024年7月6日 作者:Commas 签名:(ง •_•)ง 积跬步以致千里,积小流以成江海…… 注释:如果您觉得有所帮助,帮忙点个赞,也可以关注我,我们一起成长;如果有不对的地方,还望各位大佬不吝赐教,谢谢^ - ^ 1.01365 = 37.7834;0.99365 = 0.0255 1.02365 = 1377.4083…

Portainer工具

Portainer是一款免费、开源的Docker的图形化管理工具&#xff0c;其能够提供状态显示面板、应用模板快速部署、容器镜像网络数据卷的基本操作&#xff08;包括上传下载镜像&#xff0c;创建容器等操作&#xff09;、事件日志显示、容器控制台操作、Swarm集群和服务等集中管理和…

ST Smart Things Sentinel:一款针对复杂IoT协议的威胁检测工具

关于ST Smart Things Sentinel ST Smart Things Sentinel&#xff0c;简称ST&#xff0c;是一款功能强大的安全工具&#xff0c;广大研究人员可以使用该工具检测物联网 (IoT) 设备使用的复杂协议中的安全威胁。 在不断发展的联网设备领域&#xff0c;ST Smart Things Sentinel…

揭秘反向沙箱:企业网络安全的终极防线

通常&#xff0c;我们讨论的沙箱环境分为正向沙箱和反向沙箱。那么什么正向沙盒反向沙盒到底是什么呢&#xff1f; 正向沙箱通常用于分析来自外部的未知文件、电子邮件附件、网页内容等&#xff0c;以检测其中是否包含恶意软件或有害代码。这种沙箱通常位于企业的防火墙之外&am…

鸿蒙next 下拉刷新上来加载 来了 我不允许你不会

前言 各位同学大家好, 有段时间没有给大家更新文章了 ,最近在开发 鸿蒙next中 有用到这个下拉刷新和上来加载的功能就准备写个文章分享一下 那么废话不多说 我们正式开始: 效果图 准备工作: 找到我们DevEco studio 的安装位置 找到我们ohpm 的bin目录 配置在环境变了中 …

Plotly.js带颜色比例的轮廓图

本文由ScriptEcho平台提供技术支持 项目地址&#xff1a;传送门 Plotly.js Contour Plot with Color Scale 应用场景 Contour plot 是一种可视化数据分布的图表&#xff0c;常用于气象学、地球物理学和医学成像等领域。它通过绘制等值线来展示数据的变化&#xff0c;帮助用…

Flink异常:org/apache/hadoop/hive/ql/parse/SemanticException

在flink项目中跑 上面这段代码出现如下这个异常&#xff0c; java.lang.NoClassDefFoundError: org/apache/thrift/TException 加上下面这个依赖后不报错 <dependency> <groupId>org.apache.thrift</groupId> <artifactId>libthrift</artifactId…

水库大坝安全监测险情应对措施

汛期暴雨洪涝灾害发生后&#xff0c;为保证大坝及下游人民生命财产安全&#xff0c;应及时进行大坝安全现场检查和快速评估。评估内容包括大坝沉降和水平变形、裂缝、坝坡是否塌滑、下游坡是否存在集中渗漏或大面积渗水、溢洪道启闭设备能否正常运行、近坝库岸是否有大的滑坡体…

[激光原理与应用-110]:南京科耐激光-激光焊接-焊中检测-智能制程监测系统IPM介绍 - 13 - 德擎激光焊接在线缺陷检测系统 WDD详解解析

目录 一、产品简介 1.1 概述 1.2 多光学信号传感器 &#xff08;1&#xff09;外观 &#xff08;2&#xff09;消费电子行业应用 1.3 IO信号处理模块/可编程控制模块 1.4 操作系统分析软件 1.5 检测原理分析 二、硬件原理 2.1 系统架构与电路接口 2.2 多光学信号传感…

链路聚合概述

技术背景&#xff1a; 随着网络规模不断扩大&#xff0c;人们对骨干链路的带宽吞吐量与可靠性提出了越来越高的要求。根据传统的方案&#xff0c;只能将当前链路更换为更高速的链路。但是更换链路需要付出较高的成本费用&#xff0c;而且灵活性差&#xff0c;因此我们需要探索…

ERROR: No matching distribution found for matplotlib

1.问题&#xff1a;安装matplotlib报错&#xff0c;如下图所示&#xff1a; 2.通过换源&#xff0c;输入以下命令&#xff1a;python -m pip install matplotlib -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com&#xff0c;但是还是无效 3.在pycharm中升级…

OpenHarmony 入门——ArkUI自定义组件的基础语法(一)

文章大纲 引言一、自定义组件的基本语法1、Component 装饰器 和 Entry 装饰器2、build函数3、Reuseable4、定义成员函数/变量 二、自定义组件的使用 引言 在OpenHarmony 系统里ArkUI子系统显示的内容均为组件&#xff0c;由框架直接提供的称为系统组件&#xff0c;由开发者定义…

本地服务器部署外网可访问地址

一、开放服务器端口 &#xff08;1&#xff09;打开【控制面板】-【系统和安全】-【防火墙】-【高级设置】 &#xff08;2&#xff09;右键【新建规则】-【端口】-【程序&#xff1a;所有程序】-【操作&#xff1a;允许连接】-【配置文件&#xff1a;默认】-【名称&#xff1a;…

Customize-A-Video:文生视频自由定制

视频领域&#xff0c;尤其是文本到视频&#xff08;T2V&#xff09;扩散模型中的动作定制&#xff0c;尚未得到充分研究。来自马里兰大学、Adobe Research 和延世大学的研究团队提出了一种名为“Customize-A-Video”的新方法&#xff0c;本方法通过单一参考视频对动作进行建模&…

20240713 每日AI必读资讯

&#x1f697; 烧钱抢老司机饭碗&#xff1f;“萝卜快跑”事件辟谣 - 武汉相关负责人辟谣&#xff1a;无人车不是1000辆&#xff0c;只有400多辆 - “萝卜快跑”自动驾驶车可以通过单车智能、多重安全系统冗余保障以及5G云代驾平行驾驶三重冗余保障&#xff0c;确保自动驾驶…

vue学习day07-scoped样式冲突、data是一个函数、props详解、组件通信、非父子通信-event bus 事件总线

19、scoped样式冲突 &#xff08;1&#xff09;默认情况&#xff1a;写在组件中的样式会全局生效&#xff0c;因此会很容易造成多个组件之间的样式冲突问题。 1&#xff09;全局样式&#xff1a;默认组件中的样式会作用到全局 比如&#xff1a; 当只有box1设置边框时&#…

外贸国际短信群发工具的开发源代码!

在外贸行业中&#xff0c;快速、准确地与客户进行沟通是业务成功的关键之一&#xff0c;随着科技的不断进步&#xff0c;国际短信群发工具成为了外贸从业者不可或缺的工具。 本文将通过科普五段源代码&#xff0c;带您深入了解外贸国际短信群发工具的开发原理和实现过程。 一…

【题目/训练】回溯算法练习

&#x1f342;八皇后 二进制来表示。 #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <unordered_map> using namespace std;int n; #define MASK(n) ((1<<(n1))-2) //如 6 得到的是1000 0000 …