关于实现以下功能的代码。
1.变量i可以通过Atest:getint()得到。
2.变量i只允许继承了他的B修改。
3.维持B员工能不变。
如果哪位大神有更好的方法请告诉我 谢谢。
// test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "iostream"
#include "memory"
using namespace std;
class Atest
{
public:
static int getint(){return i;}
protected:
void setint(int value)
{
i = value;
}
private:
static int i ;
};
class Ctest
{
public:
int ztest()
{
cout << "asd" << endl;
return 0;
};
};
class Btest :public Atest,public Ctest
{
public:
Btest(){};
~Btest(){};
void test()
{
cout << getint() << endl;
setint(5);
cout << getint() << endl;
//cout << Atest::i << endl;
}
void ssss()
{
setint(3);
}
};
int Atest::i ;
int _tmain(int argc, _TCHAR* argv[])
{
Btest * B = new Btest();
B->ssss();
B->test();
B->ztest();
cout << Atest::getint() << endl;
while (1)
{
}
return 0;
}