class declaration c++ code example
Example 1: how to write a class in c++
class Rectangle
{
int width, height;
public:
void set_values (int,int);
int area() {return width*height;}
};
void Rectangle::set_values (int x, int y)
{
width = x;
height = y;
}
Example 2: classes c++
class Rectangle {
int width, height;
public:
void set_values (int,int);
int area (void);
} rect;
Example 3: classes c++
class class_name {
access_specifier_1:
member1;
access_specifier_2:
member2;
...
} object_names;
Example 4: create class instance c++
MyClass* MyObject = new MyClass();
Example 5: c++ classes
class SampleClass
{
int a;
public:
SampleClass(int v)
{
a=v;
}
int RetVal()
{
return a;
}
};
Example 6: new class * [] c++
class Circle {
private:
double radius;
......
public:
void setRadius(double radius) {
this->radius = radius;
}
......
}