一些常见的运算符重载
来源:互联网 发布:数控车床手工编程入门 编辑:程序博客网 时间:2024/06/05 18:57
#include<iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<malloc.h>using namespace std;class my_complex{public:void * operator new(size_t size){ void *p = (void *)malloc(size); if(NULL != p) { cout << "operator new rom is sucess!"<< endl; return p; }}void operator delete (void *p){free(p);}public :void get_data(void ){cout << "real = "<< real<<endl;cout << "virt = "<< virt << endl;}private: double real; double virt;public:my_complex(){} my_complex(double x,double y){ real = x;virt = y;}my_complex (my_complex & sd){real = sd.real;virt = sd.virt;}my_complex operator = (my_complex &sd){if(this != &sd){real = sd.real;virt = sd.virt;}return *this;} ~my_complex(){}};int main(){ my_complex a;char str[10];my_complex::operator new (sizeof(str));return 0;}
运行结果:
operator new rom is sucess!Press any key to continue
<div style="top: 654px;"></div><div style="top: 654px;">输入输出运算符的重载</div><div style="top: 654px;"></div><div style="top: 654px;"></div><div style="top: 654px;">#include<iostream> #include<stdio.h>#include<stdlib.h></div><div style="top: 654px;">using namespace std; class value { public: //构造函数 value() { value1=0; value2=0; } value(int v1,int v2) { value1=v1; value2=v2; } //重载output friend ostream &operator<< (ostream &output,const value &sw) { output<<"v1="<<sw.value1<<" "<<"v2="<<sw.value2; return output; } //重载input friend istream &operator>> (istream &input,value &sw) { input>>sw.value1>>sw.value2; return input; } private: int value1; int value2; }; int main() { value sw1(10,20),sw2(5,8),sw3; cout<<"Enter sw3:"<<endl; cin>>sw3; cout<<"sw1:"<<sw1<<endl; cout<<"sw2:"<<sw2<<endl; cout<<"sw3:"<<sw3<<endl; return 0; } </div><div style="top: 654px;"></div>
0 0
- 重载一些常见的运算符
- C++一些常见的运算符重载
- 一些常见的运算符重载
- 运算符重载的一些注意事项
- 【C++】一些基本的运算符的重载
- [C++]关于重载运算符的一些建议
- Python中常见运算符重载方法
- 【C++学习笔记】常见运算符重载
- 运算符的重载:[],(),->;
- 运算符的重载
- 运算符的重载
- 运算符的重载
- 运算符的重载
- “[]”运算符的重载
- 运算符的重载
- 运算符的重载
- 运算符的重载
- 运算符的重载
- HttpClient系统日志配置
- light oj 1214 - Large Division (同于定理--整除运算)
- Poj 3903 Stock Exchange(LIS)
- Python装饰器与面向切面编程
- Git和Egit安装使用总结
- 一些常见的运算符重载
- TOJ 2142.Pascal Library
- PHP如何实现网址伪静态
- 王学岗app架构设计-MVP
- 【16.50%】【CF 44G】Shooting Gallery
- 第44课:Spark 2.0编程实战之DataSet案例开发实战
- 工具类:ehCache,用于缓存
- 面试宝典第6章_ 2(const) const 成员函数 ,const 与define定义的不同
- PHP实现伪静态化页面的具体实现方式