14 - Constructors

2017-12-30  本文已影响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();

上一篇 下一篇

猜你喜欢

热点阅读