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

最新文章

  1. C++ 引用计数技术及智能指针的简单实现
  2. SQL SERVER导出特殊格式的平面文件
  3. 40 个顶级 jQuery 图片、内容滑块和幻灯片(转)
  4. 使用DNSPod来处理网站的均衡负载(转)
  5. mysql 强制走索引
  6. CKEditor 案例
  7. 软件设计模式详解:OCP原则
  8. [小程序开发] 微信小程序内嵌网页web-view开发教程
  9. java 数据分页
  10. docker学习(一)
  11. PHP 数据库连接池实现
  12. FSFS和VDFS存储方式的区别
  13. 无法创建保存文件 &quot;afiedt.buf&quot;
  14. Springboot的日志管理&amp;Springboot整合Junit测试&amp;Springboot中AOP的使用
  15. bresenhan算法数学推导
  16. 【链接】linuxCentOS权限问题修复(chmod777-R或者chmod755- http://www.cnblogs.com/kofxxf/p/5220836.html
  17. aliyun EC2配置利用filezilla配置ftp服务
  18. javascript:Array.prototype.slice.call(arguments)
  19. Activity四种启动模式之singleTask应用
  20. redis-3.0.0_rc5的RPM包制定

热门文章

  1. java中String转换成json,json转换成String
  2. 01.Django-基础
  3. 前端基础进阶(十五):详解 ES6 Modules
  4. [JavaWeb基础] 012.Struts2 自定义标签使用
  5. 节点流(文件流) FileInputStream &amp; FileOutputStream &amp; FileReader &amp; FileWriter
  6. Rocket - config - DefaultConfig
  7. 带你学够浪:Go语言基础系列-环境配置和 Hello world
  8. Java实现 蓝桥杯 算法提高VIP 摆花 dp 记忆搜索 2种做法 多重背包
  9. Java实现 LeetCode 647 回文子串(暴力)
  10. Java实现 LeetCode 429 N叉树的层序遍历