c++ classes and methods code example
Example 1: c++ class method example
class Object {
public:
int var;
void setVar(int n) {
var = n;
}
int getNum() {
return var;
}
};
int main() {
Object obj;
obj.setVar(13);
std::cout << obj.getNum() << std::endl;
return 0;
}
Example 2: classes c++
class Rectangle {
int width, height;
public:
void set_values (int,int);
int area (void);
} rect;