How to create a class in cpp?

How to create a class in cpp?

using namespace std;
class myclass{
int name(int a,int b);  //this is function 

int myclass::name(int a,int b)  //This is a member function 
        cout <<a;
    return 0;
int main()
    myclass obj;    // myclass object is obj,50);     //a=30,b=50

In the myclass declaration, the member function name is declared to take two integer parameters a and b and return an integer. The function is not defined within the class declaration, but its definition is provided later in the code.

The definition of the name function begins with int myclass::name(int a, int b), indicating that it is a member function of the myclass class. Inside the function, there is an if statement that checks if a is greater than b. If this condition is true, it prints the value of a using cout. Otherwise, it prints the value of b.

The main function is where the program starts executing. It creates an object of the myclass class called obj. Then, it calls the name function on the obj object, passing the values 30 and 50 as arguments. This will invoke the name function, and depending on the values of a and b, it will print either 30 or 50 to the console.

Read More Details

object-oriented programming

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
NEW TOXIC ROCKET CYCLE DECK in Clash Royale 2023 Best Deck in Clash Royale Best Deck for Arena 8 in Clash Royale Best Hog deck for Pro players Best Clash Royale Deck