美文网首页
14 - Constructors

14 - Constructors

作者: 社交帐号直接注册 | 来源:发表于2017-12-30 23:09 被阅读0次

GitHub

1.

class BuckysClass{

public:

BuckysClass(){

cout << "this will get printed automatically";

}

void setName(string x){

name=x;

}

string getName(){

return name;

}

private:

string name;

};

BuckysClass bo;

//this will get printed automatically

2.

class BuckysClass{

public:

BuckysClass(string z){

setName(z);

}

void setName(string x){

name=x;

}

string getName(){

return name;

}

private:

string name;

};

BuckysClass bo("Lucky Bucky roberts");

cour << bo.getName();

BuckysClass bo2("Sally mcSalad");

cour << bo2.getName();

相关文章

网友评论

      本文标题:14 - Constructors

      本文链接:https://www.haomeiwen.com/subject/ikangxtx.html