c++ cc24a_demo //转换函数,用来做转换操作符,int()括号里面必须是空的,必须定义为const,代码示范
2024-08-31 09:43:05
c++ cc24a_demo //转换函数,用来做转换操作符,int()括号里面必须是空的,必须定义为const,代码示范
#include <iostream>
#include <string>
using namespace std; class Dog
{
public:
Dog(string n, int a, double w) :name(n), age(a), weight(w) {}
operator int() const//转换函数,用来做转化操作符,int()括号里面必须是空的,必须定义为const
{
return age;
}
operator double() const//转换函数
{
return weight;
}
operator std::string() const//转换函数
{
return name;
}
private:
int age;
double weight;
string name;
}; int main()
{
int a, b;
a = ;
b = a;
Dog d("Bill",,15.0);
b = d; //d得到的是整形,调用转换函数,operator int()
cout << b << endl; getchar();
return ;
}
最新文章
- C++ 引用计数技术及智能指针的简单实现
- SQL SERVER导出特殊格式的平面文件
- 40 个顶级 jQuery 图片、内容滑块和幻灯片(转)
- 使用DNSPod来处理网站的均衡负载(转)
- mysql 强制走索引
- CKEditor 案例
- 软件设计模式详解:OCP原则
- [小程序开发] 微信小程序内嵌网页web-view开发教程
- java 数据分页
- docker学习(一)
- PHP 数据库连接池实现
- FSFS和VDFS存储方式的区别
- 无法创建保存文件 ";afiedt.buf";
- Springboot的日志管理&;Springboot整合Junit测试&;Springboot中AOP的使用
- bresenhan算法数学推导
- 【链接】linuxCentOS权限问题修复(chmod777-R或者chmod755- http://www.cnblogs.com/kofxxf/p/5220836.html
- aliyun EC2配置利用filezilla配置ftp服务
- javascript:Array.prototype.slice.call(arguments)
- Activity四种启动模式之singleTask应用
- redis-3.0.0_rc5的RPM包制定
热门文章
- java中String转换成json,json转换成String
- 01.Django-基础
- 前端基础进阶(十五):详解 ES6 Modules
- [JavaWeb基础] 012.Struts2 自定义标签使用
- 节点流(文件流) FileInputStream &; FileOutputStream &; FileReader &; FileWriter
- Rocket - config - DefaultConfig
- 带你学够浪:Go语言基础系列-环境配置和 Hello world
- Java实现 蓝桥杯 算法提高VIP 摆花 dp 记忆搜索 2种做法 多重背包
- Java实现 LeetCode 647 回文子串(暴力)
- Java实现 LeetCode 429 N叉树的层序遍历