User2018
10
Q:

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;
}
5
class MyClass {       
  // The class
  public:             
  // Access specifier
    int myNum;        // 
  Attribute (int variable)
    string myString;  // 
  Attribute (string variable)
};
1
class Rectangle {
    int width, height;
  public:
    void set_values (int,int);
    int area (void);
} rect;
1
class class_name {
  access_specifier_1:
    member1;
  access_specifier_2:
    member2;
  ...
} object_names;
0
TYPE& dynamic_cast<TYPE&> (object);
TYPE* dynamic_cast<TYPE*> (object);
-3

New to Communities?

Join the community