C++构造函数2
发布日期:2022-02-22 18:04:11 浏览次数:7 分类:技术文章

本文共 544 字,大约阅读时间需要 1 分钟。

一、构造函数分类

  普通构造函数,复制(拷贝)构造函数,赋值构造函数,

#include 
using namespace std;class A {public: A() { a = 0; }//普通 A(const A&other) {
//复制 this->a = other.a; } A &operator=(const A & other) {
//赋值 this->a = other.a; return *this; }A(double convert) {
//转换构造函数 this->a = int(convert);}private: int a;};int main(){ A a, b;//调用普通构造函数 A c = b;//调用复制构造函数 c = a;//调用赋值构造函数 A d(c);//调用赋值构造函数double e = 0.1;A f(e); return 0;}

转载于:https://www.cnblogs.com/MyBlog-Richard/p/5994956.html

转载地址:https://blog.csdn.net/dengsigukan55762/article/details/101976089 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Java中接口的实现问题
下一篇:C++构造函数

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月02日 02时57分29秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章