* Box.h
*
* Created on: 2018年12月13日
* Author: weihan
*/
#include<string>
#ifndef BOX_H_
#define BOX_H_
using namespace std;
class Box {
public:
int publicint,age;
string name;
Box(int a = 0, string name = "ab");
virtual ~Box(); //类的析构函数是类的一种特殊的成员函数,它会在每次删除所创建的对象时执行。
static int staticint;
static string staticstring;
static string getpubstring() {
return staticstring;
}
public:
int pubint = 10;
string pubstr = "abc";
private:
int priint = 11;
protected:
string prtint = "bcsd";
};
Box::Box(int age, string name) {
// this。age =age ; 错
this->name=name;
}
Box::~Box() {
}
int Box::staticint = 1000;
string Box::staticstring = "bcddfsfadf";
int main() {
Box box1(1, "abc");
Box box2(11, "efg");
Box * pBox;
pBox = &box1;
cout << Box::getpubstring() << endl; //:: 应该是命名空间的意思,命名空间内
cout << pBox->pubstr << endl;
cout << box1.publicint << endl;
// cout << box1->publicint << endl; 错
// cout << pBox.pubstrt << endl; 错
}
#endif /* BOX_H_ */```
网友评论