类 代码示范
#include<iostream> using namespace std; class Box{ private: double length; double width; public: void setLength(double length); void setWidth(double width); double getLength(); double getWidth(); double getArea(); }; void Box::setLength(double length) { this->length=length; } void Box::setWidth(double width) { this->width=width; } double Box::getArea() { return length*width; } double Box::getLength() { return length; } double Box::getWidth() { return width; } int main() { Box box; box.setLength(6.0); box.setWidth(7.0); cout<<box.getArea()<<endl; return 0; }