cppTest-7.4:对象赋值与重载赋值运算符=

/**
 *cppTest-7.4:对象赋值与重载赋值运算符=
 *
 *需要说明的是,关于赋值运算符重载的函数定义并不是必须的。
 *此外,在C++中,程序员不能定义新的运算符,被重载的运算符保持原有的优先级和结合性,而不论运算符重载函数内代码是什么样的形式。
 *对于赋值操作,必须返回表达式的值,也即等式右边的值,只有这样,才能使连续赋值如c=b=a合法。程序中是通过返回由this指向的对象来实现的。
 *author 炜sama
 */

#include<iostream.h>
class three_d{
	int x,y,z;
public:
	three_d(int x1=0,int y1=0,int z1=0){ x=x1;   y=y1;   z=z1;}
	//如果进行对象的赋值运算的话(比如c=c2),则此时系统将自动调用缺省的类似于下面的赋值运算符重载函数:
	three_d operator=(three_d &t)
	{
		x=t.x;   y=t.y;   z=t.z;
		return *this;//@@this为指针,而complex不是指针,所以要取指针内容然后返回:*this!!
	}
	void show(){ cout<<"("<<x<<","<<y<<","<<z<<")"<<endl;}
	friend three_d operator+(three_d &d1,three_d &d2);
};
three_d operator+(three_d &d1,three_d &d2)
{
	int x1,y1,z1;
	x1=d1.x+d2.x;
	y1=d1.y+d2.y;
	z1=d1.z+d2.z;
	return three_d(x1,y1,z1);
}
void main()
{
	three_d a(1,2,3),b(10,10,10);
	three_d c;
	a.show();   b.show();
	c=a+b;      c.show();
	c=a+b+c;    c.show();
	c=b=a;      c.show();      b.show();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误的原因是在运行"./Log4cppTest"时,系统无法找到共享库"liblog4cpp.so.5",导致无法打开共享对象文件。 解决这个问题的方法是确保"liblog4cpp.so.5"库文件存在于系统的共享库路径中,并且路径已正确配置。您可以通过以下步骤来解决这个问题: 1. 首先,确认您已经安装了"liblog4cpp.so.5"库文件。您可以在终端中使用以下命令来查找该文件: ``` $ find / -name liblog4cpp.so.5 ``` 如果该文件存在,则会返回文件的路径。如果不存在,您需要下载并安装该库文件。 2. 一旦确认库文件存在,您需要将其路径添加到系统的共享库路径中。可以通过以下命令将库文件路径添加到/etc/ld.so.conf文件中: ``` $ sudo echo "/path/to/liblog4cpp.so.5" >> /etc/ld.so.conf ``` 请将"/path/to/liblog4cpp.so.5"替换为实际的库文件路径。 3. 更新共享库缓存,使系统能够找到新添加的库文件路径: ``` $ sudo ldconfig ``` 现在,您应该可以成功运行"./Log4cppTest",而不再出现"error while loading shared libraries: liblog4cpp.so.5: cannot open shared object file: No such file or directory"的错误信息了。请按照上述步骤进行操作,确保路径和命令的准确性。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [VS code出现错误:g++.exe: error: Hello: No such file or directory g++.exe: error: Word.cpp: No such ...](https://blog.csdn.net/qq_45708377/article/details/112732294)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [cpptest:C++学习笔记 包括 侯捷讲解的系列CPP课程以及UNP、APUE等](https://download.csdn.net/download/weixin_42122306/19205361)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值