關於實現以下功能的代碼。
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;
}