编程学习网为您整理以下代码实例,主要实现:C++保护成员,希望可以帮到各位朋友。
#include <iostream>
using namespace std;
class Box {
protected:
double wIDth;
};
class SmallBox:Box { // SmallBox is the derived class.
public:
voID setSmallWIDth( double wID );
double getSmallWIDth( voID );
};
// Member functions of child class
double SmallBox::getSmallWIDth(voID) {
return wIDth ;
}
voID SmallBox::setSmallWIDth( double wID ) {
wIDth = wID;
}
// Main function for the program
int main() {
SmallBox Box;
// set Box wIDth using member function
Box.setSmallWIDth(5.0);
cout << "WIDth of Box : "<< Box.getSmallWIDth() << endl;
return 0;
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!