how to make class in 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: C++ class

class Personnage
{
    
}; // N'oubliez pas le point-virgule à la fin !

Example 4: class in c++

class Name {
  private:
  	int data;
  
  public:
  
    // Constructor
  	Name() {
		// Code      
    }
  	int id;
  	void fun1(int a) {
        // Some instructions here 
    }
 	 
}

Tags:

Cpp Example