c 运算符重载前置++_C ++运算符重载–综合指南

c 运算符重载前置++

Hello, folks! In this article, we will understand a very interesting yet magical power provided by C++Operator Overloading.

大家好! 在本文中,我们将了解C ++提供的一种非常有趣但不可思议的功能- 运算符重载



操作员重载入门 (Getting started with Operator Overloading)

Operator overloading provides the ability to a mathematical operator to perform other manipulation operations other than its original operation.

运算符重载为数学运算符提供了执行除原始运算以外的其他运算操作能力

For example, the '+' operator is used for arithmetic addition purpose, but with the help of operator overloading, we can use ‘+’ operator to concatenate two strings at runtime efficiently.

例如, '+' operator用于算术加法,但借助运算符重载,我们可以使用“ +”运算符在运行时有效地连接两个字符串。

Thus, C++ has the ability to make operators work into different dimensions to perform various operators other than the designated operation of its own.

因此,C ++能够使运算符工作于不同的维度,以执行除自身指定的运算符以外的各种运算符。

Syntax:

句法:


Class_name operator_keyword operator_symbol(Class_name object)

We will get to know more about the syntax and usage further in this article.

我们将在本文中进一步了解语法和用法。

Example:

例:


#include<iostream>  
#include<conio.h>
#include<string.h>
using namespace std;  
  
class Concatenate  
{  
    char inp_str[100];  
public:  
    void enter_string() 
    {  
        cout<<"Input the string: ";  
        cin>>inp_str;  
    }  
    void show_string()  
    {  
        cout<<inp_str;  
    }  
    Concatenate operator+(Concatenate St)  
    {
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值