c++构造函数的调用方法
2024-09-02 15:12:05
#include<iostream>
using namespace std;
class Base
{
public:
Base(){
cout<<"hello"<<endl;
}
Base (int _a ):base(_a){ // 将a赋值给base
base++;
cout << base << endl;
}
Base (int _a ,float _b):base(_a),th(_b){
cout << base + th << endl;
}
Base (int _a ,float _b ,int _c):base(_a),th(_b),xh(_c){
cout << base + th + xh<< endl;
} void fun0(){cout << base << endl;}
int base;
float th;
int xh;
};
int main(){
Base b; // 调用默认构造函数
Base t(10); // 调用带参的构造函数的简写形式
t.fun0();
t.base=100;
t.fun0();
Base t1 =Base(100,88.12); // 调用带参的构造函数
Base t2 =(10,100.12,20); //
}
注意:Base t2 =(10,100.12,20); 在乌班图下输出的结果为错误的。
最新文章
- VMware安装CentOS
- 细说;(function ($, undefined){ })(jQuery); 的使用
- java.lang.RuntimeException: Method setUp in android.test.ApplicationTestCase not mocked. See http://g.co/androidstudio/not-mocked for details.
- html-5 --html5教程article、footer、header、nav、section使用
- poj 3237 Tree
- hdu 4778 Gems Fight! 博弈+状态dp+搜索
- android 在Fragment里添加Theme主题
- LightOj 1230 Placing Lampposts(树形DP)
- LeetCode :: Insertion Sort List [具体分析]
- 关于boostrap的thead固定tbody滚动
- BZOJ USACO 银组 水题集锦
- [转][RabbitMQ+Python入门经典] 兔子和兔子窝
- JDK各个版本的新特性
- eclipse中的项目为什么无法添加到tomcat中?
- [nodejs] nodejs开发个人博客(一)准备工作
- Spring AOP详细介绍
- treap学习笔记
- MySQL存储过程 事务transaction
- keras环境
- WCF无法引入Model实体解决方案