m nt understanding how can i make main of a class

Recommended Answers

In C++, the main function doesn't go in a class. Maybe you're thinking of Java.

Jump to Post

All 2 Replies

In C++, the main function doesn't go in a class. Maybe you're thinking of Java.

Do you mean the constructor?

You make a public function within the class that has no return (not void) and also has the same name as the class.

#include <iostream>
using namespace std;

class Square
{
    int _side;

public:

    Square(){};

    Square(int side)
    {
        _side = side;
    }
};

int main()
{
    Square aSquare;
    Square bSquare(10);

    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.