您的位置:首页 > 其它

explicit关键字的使用

2016-03-06 15:16 330 查看
#include<iostream>
#include<string>

using namespace std;

class Student{
public:
Student(int age){
this->age = age;
cout<<this->age<<endl;
}
private:
int age;
};

class Teacher{
public:
explicit Teacher(int age){
this->age = age;
cout<<this->age<<endl;
}
private:
int age;
};

int main(){
Student zhang(23);
Student wang = 43;
Teacher xue = Teacher(50);
//  Teacher zhao = 50;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: